Example: rmarkdown

Read yaml header parameters

yml = rmarkdown::yaml_front_matter("~/projects/study/r/ex_r_rmarkdown.Rmd")
str(yml)
#> List of 10
#>  $ title      : chr "Example: rmarkdown"
#>  $ date       : chr "2018-01-20T19:19:40+03:00"
#>  $ draft      : logi FALSE
#>  $ description: chr ""
#>  $ tags       : NULL
#>  $ categories : chr "examples r rmarkdown"
#>  $ type       : chr "post"
#>  $ url        : NULL
#>  $ author     : chr "Mert Nuhoglu"
#>  $ output     : chr "rmarkdown::html_document"

yaml header parameters in raw format are here:

cat ~/projects/study/r/ex_r_rmarkdown.Rmd | head 
## ---
## title: "Example: rmarkdown"
## date: '2018-01-20T19:19:40+03:00'
## draft: false
## description: ""
## tags:
## categories: examples r rmarkdown
## type: post
## url:
## author: "Mert Nuhoglu"

Find external resource references / dependencies

Assume that I have an external dependency such as the following code:

cat ./globals.R

When first run, find_external_resources() couldn’t find external dependencies:

rmarkdown::find_external_resources("~/projects/study/r/ex_r_rmarkdown.Rmd")
#> [1] path     explicit web     
#> <0 rows> (or 0-length row.names)

Then I added the following parameter to the yaml header of the Rmd file:

resource_files:
- ./globals.R
df = rmarkdown::find_external_resources("~/projects/study/r/ex_r_rmarkdown.Rmd")
df
#>        path explicit   web
#> 1 globals.R     TRUE FALSE
str(df)
#> 'data.frame':    1 obs. of  3 variables:
#>  $ path    : chr "globals.R"
#>  $ explicit: logi TRUE
#>  $ web     : logi FALSE

 Tech    20 Dec, 2017

Any work (images, writings, presentations, ideas or whatever) which I own is always provided under
Creative Commons License Creative Commons Attribution-Share Alike 3.0 License

Mert Nuhoglu is a Trabzon-born programmer and data scientist.

You may also like...