Skip to contents

Get Frequency of String Constant Usage in R Scripts

Usage

get_string_constants_in_scripts(
  root,
  scripts = dir(root, "\\.[Rr]$", recursive = TRUE),
  two_version_check = TRUE,
  FUN = NULL
)

Arguments

root

path to folder in which to look for R scripts

scripts

optional. Paths to R scripts in which to search for string constants, relative to root

two_version_check

if TRUE (default), two different implementations of this function are used and the results are compared internally. Set this argument to FALSE to get the result as fast as possible.

FUN

optional. Function used to browse the code tree for string constants. If NULL (the default), kwb.code:::fetch_string_constants_1 is used.

Value

data frame with columns file_id (file identifier),

string (string constant found in the file) and count (number of occurrences of the string counted in the file). The file identifier can be resolved to a full file name using the "file database" that is stored in the attribute "file_db".

Examples

root <- system.file(package = "kwb.code")
constants <- get_string_constants_in_scripts(root)
#> Splitting paths ... ok. (0.00 secs) 
#> Removing the first 7 path segments ... ok. (0.00 secs) 
#> Reading /Users/runner/work/_temp/Library/kwb.code/extdata/cleanCodeBasics.R ... ok. (0.00 secs) 
#> Reading /Users/runner/work/_temp/Library/kwb.code/extdata/codeUsage.R ... ok. (0.00 secs) 
#> Reading /Users/runner/work/_temp/Library/kwb.code/extdata/testcalls_1.R ... ok. (0.00 secs) 
#> Reading /Users/runner/work/_temp/Library/kwb.code/extdata/testcalls_2.R ... ok. (0.00 secs) 

# Get paths to files from "file database" stored in attribute "file_db"
kwb.utils::getAttribute(constants, "file_db")
#> $files
#>   file_id         file_name folder_id
#> 1 file_01 cleanCodeBasics.R folder_01
#> 2 file_02       codeUsage.R folder_01
#> 3 file_03     testcalls_1.R folder_01
#> 4 file_04     testcalls_2.R folder_01
#> 
#> $folders
#>   folder_id folder_path
#> 1 folder_01     extdata
#>