sourcing and displaying R source code in R Markdown without executing -


i writing book in r markdown. saved lot of code in separate .r files. didactical purpose need show whole file's contents without running it.

e.g.,

r my_r_chunk source("./code/mycodefile.r") 

```

would rendered displaying whole content of mycodefile.r without executing it.

check out ?knitr::read_chunk

first, assign label script using syntax ## ---- your_label ---- placing in first line of script called foo.r

foo.r

## ---- your_label ----  print("hello world") 1:10 

after assigning script label, can read_chunk script in uncached chunk. reference contents in subsequent (cached) chunk using eval = false chunk option.

your_rmd_file.rmd

--- output: pdf_document ---  ```{r cache=false, echo = false} library(knitr) read_chunk('foo.r') ```  ```{r your_label, cache = true, eval=false}  ``` 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -