Extract functions from R scripts within a directory
Source:R/extract_functions.R
extract_functions.Rd
As any functions from high risk packages require testing for use in high risk products, it is important to know which functions are used in the code.
Usage
extract_functions_from_dir(dir, pattern = ".(r|rnw|rmd|qmd)$", ...)
extract_functions_from_file(file)
Value
a dataframe with the function (fun) and it's parent package (package), and accessed_via indicating whether the function was accessed directly from the namespace with `::` or `:::`, otherwise it is empty.
Details
`extract_functions_from_file` extracts functions from a single file. Where the file is a markdown (Rmd or qmd) or Sweave file (Rnw), the R code is first extracted via the `knitr::purl` function.
`extract_functions_from_dir` extracts all functions from R scripts within a directory that match a specified pattern. Specific files can be chosen via the `pattern` argument, which accepts regular expressions. Files that match `pattern` will be parsed for functions.
Note
It is important to note that functions used inside e.g. `lapply` or `sapply` are not considered functions by the code parser and may not be extracted unless they are also used directly elsewhere in the code (e.g. length will not be found if used within `lapply(..., length)`, but would be found if there was an additional use of the length function elsewhere - `length(x)`).