In R markdown (knitr package), can I access a variable within the body of the document that was calculated in a code chunk?
For example, # Say Hello to markdown . A single hashtag creates a first level header. Two hashtags, ## , creates a second level header, and so on. italicized and bold text - Surround italicized text with asterisks, like this *without realizing it* .
You can insert an R code chunk either using the RStudio toolbar (the Insert button) or the keyboard shortcut Ctrl + Alt + I ( Cmd + Option + I on macOS). There are a large number of chunk options in knitr documented at https://yihui.name/knitr/options.
Yes. You can simply call any previously evaluated variable inline.
e.g. If you had previously created a data.frame
in a chunk with df <- data.frame(x=1:10)
`r max(df$x)`
Should produce
10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With