purl()
is a
wrapper to knit(..., tangle = TRUE)
).knit(input, output = NULL, tangle = FALSE, text = NULL)purl(...)
NULL
,
this function will try to guess and it will be under the
current working directoryStangle
)text
is written into a
temporary file as input
); this argument is mainly
for test purposes onlyknit
knit('my_input.Rnw')
is usually
enough. This function will try to determine many internal
settings automatically. For the sake of reproducibility,
it is a better practice to include the options inside the
input document (to be self-contained), instead of setting
them before knitting the document. First the filename of the output document is determined
in this way: tangle = TRUE
,
Based on the file extension of the input document, a list
of patterns will be used to extract R code in the
document. All built-in pattern lists can be found in
opts_knit$get('all.patterns')
(call it
apat
). Rnw files use the list
apat$rnw
, tex uses the list
apat$tex
, brew uses apat$brew
and
HTML-like files use apat$html
(e.g. html
and md files). You can manually set the pattern
list using the knit_patterns
object, and
According to the output format
(opts_knit$get('out.format')
), a set of output
hooks will be set to mark up results from R (see
render_latex
). The output format can be
LaTeX, Sweave and HTML, etc. The output hooks decide how
to mark up the results (you can customize the hooks).
See the package website and manuals in the references to
know more about
The
The
library(knitr)
(f = tempfile(fileext = ".Rnw"))
file.copy(system.file("examples", "knitr-minimal.Rnw",
package = "knitr"), f, overwrite = TRUE)
knit(f)
## or setwd(dirname(f)); knit(basename(f))
purl(f) # extract R code only
Run the code above in your browser using DataCamp Workspace