parse_scripts: Parse all given R scripts into a tree structure

parse_scriptsR Documentation

Parse all given R scripts into a tree structure

Description

Parse all given R scripts into a tree structure

Usage

parse_scripts(
  root,
  scripts = dir(root, "\\.R$", ignore.case = TRUE, recursive = TRUE),
  dbg = TRUE
)

Arguments

root

root directory to which the relative paths given in scripts relate

scripts

relative file paths to R scripts. By default all files ending with ".R" or ".r" below the root folder (recursively) are parsed.

dbg

if TRUE debug messages are shown

See Also

to_full_script_info

Examples

## Not run: 
# Download some example code files from github...
url.base <- "https://raw.githubusercontent.com/hsonne/blockrand2/master/R/"
urls <- paste0(url.base, c("blockrand2_create.R", "blockrand2_main.R"))

targetdir <- file.path(tempdir(), "blockrand2")
targetdir <- kwb.utils::createDirectory(targetdir)

for (url in urls) {
  download.file(url, file.path(targetdir, basename(url)))
}

# By default, all R scripts below the root are parse
trees <- parse_scripts(root = targetdir)

# All elements of trees are expressions
sapply(trees, is.expression)

# Analyse the scripts on the script level
scriptInfo <- to_full_script_info(trees)

scriptInfo

# Analyse the scripts on the function level
functionInfo <- get_full_function_info(trees)

functionInfo

## End(Not run)

KWB-R/kwb.code documentation built on July 28, 2023, 5:57 p.m.