Approximately detect global and imported functions or variables from R-packages by static code analysis. Conceptually, the function inspects all files in the package R-folder and contrasts the detected (unrecognized) globals and imports against the imports listed in the NAMESPACE of the R-package. R-scripts present elsewhere in the package (i.e. not in the R-folder) are not scanned, as these are not coupled to the package NAMESPACE file.
Arguments
- 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:
globals
, list of class"checkglobalsg"
imports
, list of class"checkglobalsi"
missing_packages
, character vector with missing packages
for programmatic use, cast the returned S3-object with as.data.frame
, as.matrix
,
as.character
or as_vector
.
Examples
## from R-package folder
check_pkg(
pkg = system.file(
"unit_tests", "pkg", "testpkg",
package = "checkglobals"
)
)
#> ! Packages required but not installed: pkgA
#>
#> ── Unrecognized global functions or variables ──────────────────────────────────
#>
#> <name> <location>
#> g aaa.R#2 and 12 more...
#>
#> ── Detected imported functions or variables ────────────────────────────────────
#>
#> R6 [◼◻◻◻◻◻◻◻◻◻] 1/19
#> └─ R6Class functions1.R#132
#> grid [◼◻◻◻◻◻◻◻◻◻] 1/19
#> └─ is.unit functions1.R#35
#> methods [◼◼◼◻◻◻◻◻◻◻] 3/19
#> ├─ getMethod functions1.R#67
#> ├─ setGeneric functions1.R#48
#> └─ setMethod functions1.R#49
#> parallel [◼◼◻◻◻◻◻◻◻◻] 2/19
#> └─ pvec functions1.R#88 and 1 more...
#> stats [◼◼◼◼◼◼◻◻◻◻] 6/19
#> ├─ aggregate functions1.R#87
#> ├─ approxfun functions1.R#71
#> ├─ coef functions1.R#69 and 1 more...
#> └─ median functions1.R#31 and 1 more...
#> stats4 [◼◼◻◻◻◻◻◻◻◻] 2/19
#> └─ coef functions1.R#69 and 1 more...
#> utils [◼◼◼◼◻◻◻◻◻◻] 4/19
#> ├─ globalVariables aaa.R#1 and 1 more...
#> ├─ head functions1.R#26
#> └─ tail functions1.R#65
## from bundled R-package
# \donttest{
check_pkg(
pkg = "https://cran.r-project.org/src/contrib/tinytest_1.4.1.tar.gz",
skip_globals = "cluster"
)
#> ! Packages required but not installed: tinytest
#>
#> ── Unrecognized global functions or variables ──────────────────────────────────
#>
#> ✔ None detected
#>
#> ── Detected imported functions or variables ────────────────────────────────────
#>
#> grDevices [◼◼◻◻◻◻◻◻◻◻] 2/17
#> ├─ dev.off tinytest.R#619
#> └─ pdf tinytest.R#589
#> parallel [◼◼◼◼◼◼◼◻◻◻] 7/17
#> ├─ clusterCall tinytest.R#1046
#> ├─ clusterEvalQ tinytest.R#880 and 1 more...
#> ├─ clusterExport tinytest.R#1043
#> ├─ makeCluster tinytest.R#1030
#> ├─ parLapply tinytest.R#881
#> └─ stopCluster tinytest.R#1014
#> tinytest [◼◼◼◼◻◻◻◻◻◻] 4/17
#> ├─ at_home tinytest.R#320
#> ├─ expect_equal expectations.R#834
#> ├─ expect_equivalent expectations.R#834
#> └─ expect_null expectations.R#847
#> utils [◼◼◼◼◻◻◻◻◻◻] 4/17
#> ├─ capture.output methods.R#197
#> ├─ file_test tinytest.R#570
#> ├─ getFromNamespace tinytest.R#384
#> └─ install.packages tinytest.R#1140
# }