checkglobals {checkglobals}R Documentation

Check R-source code or R-packages for globals and imports

Description

Approximately detect global and imported functions or variables from R-scripts, folders, R-code strings or R-packages by static code analysis. This function is simply a convenience wrapper around check_source and check_pkg and the return value is the same as calling these functions directly. If called without a file, dir, text or pkg argument, the function is run in the current working directory. If the current working directory is an R-package folder, this is identical to checkglobals(pkg = "."), otherwise the behavior is the same as checkglobals(dir = ".").

Usage

checkglobals(..., include_compiled = FALSE, skip_globals = NULL)

Arguments

...

can be any one of the following arguments:

  • file, file character path to R-script to analyze, can be either a file on the local filesystem or a remote file location (e.g. a server or the web).

  • text, character R-code string to analyze.

  • dir, character path to folder with R-scripts to analyze.

  • pkg, character path to R-package, can be either:

    • a local R-package folder;

    • path to bundled (tar.gz) R-package on local filesystem;

    • remote path to bundled (tar.gz) R-package, (e.g. a remote server or the web).

include_compiled

logical value indicating if compiled functions called with .Call, .C, .External, .Fortran should be included as global variables.

skip_globals

optional character vector of names to skip/exclude as (unrecognized) global variables.

Value

list S3-object of class "checkglobals" with three components:

for programmatic use, cast the returned S3-object with as.data.frame, as.matrix, as.character or as_vector.

See Also

check_source, check_pkg

Examples

## local R-script
checkglobals(
  file = system.file(
    "unit_tests", "pkg", "testpkg", "R", "functions1.R",
    package = "checkglobals"
  )
)

## local R-folder
checkglobals(
  dir = system.file(
    "unit_tests", "pkg", "testpkg", "R",
    package = "checkglobals")
)

## R-code string
checkglobals(text = "cc <- function(m) stats::coef(m)")

## R-package from folder
checkglobals(
  pkg = system.file(
    "unit_tests", "pkg", "testpkg",
    package = "checkglobals"
  )
)

## R-script from remote location

checkglobals(
  file = "https://raw.githubusercontent.com/rstudio/shiny-examples/main/004-mpg/app.R"
)


## R-package from remote location

check_pkg(
  pkg = "https://cran.r-project.org/src/contrib/tinytest_1.4.1.tar.gz",
  skip_globals = "cluster"
)


[Package checkglobals version 0.1.0 Index]