In each .R
file in the R/
folder of a package project, for the functions
defined therein, there can corresponding examples in the .Rd
files of the
man/` folder. This function extracts those examples into a list of character
vectors, one list element for each documented function.
extract_examples(r_file_name, pkg_dir = ".", document = TRUE)
The name of the .R
file within R/
. There's no need to
specify the file path (as R/x.R
, but you can do this if you want), you
can just use x.R
for whichever file x
it is. You can also omit the .R
for convenience, however using the wrong case (e.g. .r
) will produce an
error.
The directory of the R project for this package (defaults to
current directory). This is the parent directory of R/
and man/
. In
reality, this specification is somewhat lenient and even if you are in any
sub-directory of the root, it will work (e.g. it will work if you are in
R/
or man/
). Beware that this behaviour can cause a problem if you have
an R package inside an R package (but really, you have yourself to blame if
that's the case).
Run devtools::document()
to update package documentation
before starting?
A list of character vectors.
Anything found within a \dontrun{...}
block is ignored.
# NOT RUN {
devtools::create("tempkg")
setwd("tempkg")
file.copy(system.file("extdata", "detect.R", package = "exampletestr"), "R")
devtools::document()
exampletestr::extract_examples("detect")
setwd("..")
filesstrings::dir.remove("tempkg")
# }
Run the code above in your browser using DataLab