rdd_to_txt {rdocdump} | R Documentation |
Dump Package Source, Documentationm and Vignettes into Plain Text
Description
This function produces a single text output for an R package by processing its documentation (Rd files from the package source or the documentation from already installed packages), vignettes, and/or R source code.
Usage
rdd_to_txt(
pkg,
file = NULL,
content = "all",
force_fetch = FALSE,
keep_files = "none",
cache_path = getOption("rdocdump.cache_path"),
repos = getOption("rdocdump.repos", getOption("repos"))
)
Arguments
pkg |
A
|
file |
Optional. Save path for the output text file. If set, the function will return the path to the file instead of the combined text. Defaults to |
content |
A character vector specifying which components to include in the output. Possible values are:
You can specify multiple options (e.g., |
force_fetch |
|
keep_files |
A
|
cache_path |
A |
repos |
A |
Value
A single string containing the combined package documentation, vignettes, and/or code as specified by the content
argument.
If the file
argument is set, returns the path to the file.
Examples
# Extract documentation for built-in `stats` package (both docs and vignettes).
docs <- rdd_to_txt("splines")
cat(substr(docs, 1, 500))
# set cache directory for `rdocdump`
rdd_set_cache_path(paste0(tempdir(), "/rdocdump_cache"))
# Extract only documentation for rJavaEnv by downloading its source from CRAN
docs <- rdd_to_txt(
"rJavaEnv",
force_fetch = TRUE,
content = "docs",
repos = c("CRAN" = "https://cran.r-project.org")
)
lines <- unlist(strsplit(docs, "\n"))
# Print the first 3 lines
cat(head(lines, 3), sep = "\n")
# Print the last 3 lines
cat(tail(lines, 3), sep = "\n")
# clean cache directory
unlink(getOption("rdocdump.cache_path"), recursive = TRUE, force = TRUE)