purl()
is a
wrapper to knit(..., tangle = TRUE)
).knit(input, output = NULL, tangle = FALSE, text = NULL, envir = parent.frame())purl(...)
NULL
,
this function will try to guess and it will be under the
current working directoryStangle
)new.env()
to
guarantee an empty new environment)knit
output
path is NULL
, the output is returned
as a character vector.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
,
We need a set of syntax to identify special markups for R
code chunks and R options, etc. The syntax is defined in
a pattern list. All built-in pattern lists can be found
in all_patterns
(call it apat
). First the
content of the input document is matched against all
pattern lists to automatically which pattern list is
being used. If automatic detection failed, the pattern
list will be decided based on the filename extension of
the input document. 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 or the
pat_rnw
series functions in advance 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 DataLab