For each knitr code chunk option below

  1. Add the option to the code chunk it accompanies.
  2. Rerender the file to see what the option does. If you cannot tell, rerender the file both with and without the code chunk.
  3. Describe in your own words what the option does.

eval = FALSE

carmeans1 <- colMeans(cars)
1 + 1

Description: eval = FALSE does not run the code. As a result, it does not display the results.


results = 'hide'

carmeans2 <- colMeans(cars)
1 + 1
# Hint: compare the difference between eval and results
# exists() states whether an object exists 
# with the given name
exists("carmeans1") # "created" with eval=FALSE
exists("carmeans2") # "created" with results='hide'

Description: results = 'hide' runs the code, but does not display the results. This is convenient if you would like to use the results later in a new code chunk.


echo = FALSE

plot(cars)

Description: echo = FALSE hides the code in the chunk, but displays the results of the code.


fig.width = 5, fig.height = 4
When adding multiple arguments to a code chunk, separate the arguments by a comma.

plot(cars)

Description: fig.width = 5, fig.height = 4 resize any figures made by the chunk to be 5 inches by 4 inches.


message = FALSE

# libraries like to print messages
library(forecast)

Description: message = FALSE hides any messages generated by the chunk. (When message = TRUE, the default, messages will be added to the report.)


warning = FALSE

warning("This function returns a warning!")

Description: message = FALSE hides any warnings generated by the chunk. (When message = TRUE, the default, warnings will be added to the report.)




rstudio/reportsWS documentation built on May 28, 2019, 5:42 a.m.