purl_rmd | R Documentation |
Rmd/*.Rmd
to R/*.gen.R
This function strives to provide a standardized way to convert all relevant .Rmd
files in the Rmd/
subdirectory to bare .R
files in the R/
subdirectory using knitr::purl()
. It is mainly intended for authoring R packages in the R Markdown file format.
purl_rmd(
path = ".",
add_copyright_notice = funky::config_val("add_copyright_notice"),
add_license_notice = funky::config_val("add_license_notice"),
gen_pkgdown_ref = funky::config_val("gen_pkgdown_ref"),
env = parent.frame()
)
path |
Path to the root of the package directory. |
add_copyright_notice |
Whether or not to add a copyright notice at the beginning of the generated |
add_license_notice |
Whether or not to add a license notice at the beginning of the generated |
gen_pkgdown_ref |
Whether or not to overwrite pkgdown's reference index in the configuration file |
env |
Environment to evaluate R Markdown inline code expressions in when generating the pkgdown reference index. Only relevant if
|
The generated .R
files will be named the same as the .Rmd
files plus the suffix .gen
to indicate the file was auto-generated. So the file
Rmd/foo.Rmd
for example will be converted to R/foo.gen.R
.
The R Markdown file format allows you to intermingle code with related prose in Markdown syntax optimized for human readability. This facilitates (best) practices which are commonly referred to as literate programming.
In practice, the main advantage of writing R code in R Markdown is that you don't have to rely on
#
comments to explain, annotate or otherwise elaborate on your code. It also
allows you to easily compile your source code to beautifully looking HTML, PDF etc. files using rmarkdown::render()
.
This function is registered as an RStudio add-in, allowing RStudio users to assign a custom shortcut to it and to invoke it from the command palette.
path
, invisibly.
purl_rmd()
does not generate an .R
file for each and every R Markdown file in the Rmd/
subdirectory. Two types of .Rmd
files are excluded from
purling:
Files having the suffix .nopurl
in their name, e.g. Rmd/playground.nopurl.Rmd
.
Hidden files as per Unix convention whose names start
with a dot, e.g. Rmd/.playground.Rmd
.
The above convention allows for easy exclusion of specific .Rmd
files from purling. A common case for this are scripts that generate package-internal data from raw sources. Such a script could be stored as Rmd/data.nopurl.Rmd
, so that no corresponding file
under R/*.R
is generated. For the sake of clarity, it's generally advised to prefer the .nopurl
suffix over hiding files.
Other high-level functions:
lint_rmd()
,
load_pkg()
,
process_pkg()
,
run_nopurl_rmd()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.