Include Code

Inline Code

Implementing R Code in the Text is especially neat to be consistent. Maybe your data set changes and you want to implement the new summary in your file? With Word or \(\LaTeX\) you would have to search for the numbers that changed manually, which is really prone to mistakes. In R Markdown there is non of that. You just insert your R code directly in your text like that:

A typical sentence in my results section contained exactly that:

  • The final model has a test set MSE of r round(final_forest$MSE, digits = 2), ...
  • The final model has a test set MSE of 2.51, …

or

  • In total there were r format(nrow(your_data), big.mark =",") observations, ...
  • In total there were 42,378 observations, …

Code Chunks

If you want to present a code block that you used, or you have to generate a plot, you can insert a code chunk with the keyboard shortcut Strg + Alt + i.

40+2
## [1] 42

In the example you can see the command echo = TRUE. If you set echo = FALSE, you will only see the result and not the code. You can set your default in the YAML header.