Free Access Week - Data Engineering + BI
Data Engineering and BI courses are free this week!
Free Access Week - Jun 2-8

exampletestr (version 1.3.1)

extract_examples: Extract examples lines from the functions in a .R file of a package.

Description

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.

Usage

extract_examples(r_file_name, pkg_dir = ".", document = TRUE)

Arguments

r_file_name

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.

pkg_dir

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).

document

Run devtools::document() to update package documentation before starting?

Value

A list of character vectors.

Details

Anything found within a \dontrun{...} block is ignored.

Examples

Run this code
# 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