Print method for S3-objects of class "checkglobalsg" characteristic to the "globals"
list element of "checkglobals" objects returned by checkglobals,
check_pkg or check_source.
Usage
# S3 method for class 'checkglobalsg'
print(x, format = "basic", pattern, ...)Arguments
- x
object inheriting from class
"checkglobalsg".- format
character, one of the following two choices:
"basic", (default) prints only the name and source code location of the detected globals."detail", prints the name and location of the detected globals, as well as the lines in the source code file comprising the detected globals. The maximum number of lines printed per source code reference can be specified usingmaxLines.
- pattern
an optional regular expression. Only names matching
patternare returned.glob2rxcan be used to convert wildcard patterns to regular expressions.- ...
additional arguments to configure the printed output. The following arguments can be specified:
all.names, a logical value. IfTRUE, all object names are returned. IfFALSE, names which begin with a . are omitted. Defaults toTRUE.includePkgs, a character vector of imported package names. Only the imports for these packages are printed. Defaults toNA, which includes all detected packages in the printed output.maxRef, the maximum number of printed source code references per detected global/import. Defaults to 1.maxLines, the maximum number of printed lines per source code reference, only used ifformat = "detail". Defaults to 5.use_cli, a logical value indicating ifclishould be used to format the printed output. Defaults toTRUE, which means thatcli-formatting is attempted ifcliis installed.maxWidth, the maximum column width of the printed output. Ifcliis installed, the default width is determined bycli::console_width(). Ifcliis not installed,getOption("width")is checked. IfgetOption("width")is undefined, the column width defaults to 80.
Value
Returns the object x invisibly (via invisible)
Examples
## R-package from folder
chk <- checkglobals(
pkg = system.file(
"unit_tests", "pkg", "testpkg",
package = "checkglobals"
)
)
chk$globals
#>
#> ── Unrecognized global functions or variables ──────────────────────────────────
#>
#> <name> <location>
#> %>%() functions1.R#97
#> fAttach2() aaa.R#13
#> fLoad2() functions1.R#156
#> g aaa.R#2 and 13 more...
## print globals with references to source code
print(chk$globals, format = "detail", maxRef = 99)
#>
#> ── Unrecognized global functions or variables ──────────────────────────────────
#>
#> <name> <location>
#> %>%() functions1.R#97
#> fAttach2() aaa.R#13
#> fLoad2() functions1.R#156
#> g aaa.R#2 and 13 more...
#>
#> ── Global source code references ───────────────────────────────────────────────
#>
#> • %>% at functions1.R#97:
#> 97: y %>%
#> 98: sapply("g", n = 1)
#> • fAttach2 at aaa.R#13:
#> 13: fAttach2(x)
#> • fLoad2 at functions1.R#156:
#> 156: fLoad2(y)
#> • g at aaa.R#2:
#> 2: utils::globalVariables(g)
#> g at functions1.R#5:
#> 5: ff1(g + y)
#> g at functions1.R#23:
#> 23: requireNamespace(g)
#> g at functions1.R#85:
#> 85: g
#> g at functions1.R#89:
#> 89: do.call(args = list(y), what = "g")
#> g at functions1.R#90:
#> 90: lapply(FUN = "g", 1, n = 1)
#> g at functions1.R#91:
#> 91: lapply(X = 1, "g")
#> g at functions1.R#92:
#> 92: Map("g", 1, n = 1)
#> g at functions1.R#93:
#> 93: stats::aggregate(x ~ ., data = y, FUN = "g")
#> g at functions1.R#94:
#> 94: pvec(1, "g")
#> g at functions1.R#96:
#> 96: parallel::pvec(mc.cores = 1L, 1, "g")
#> g at functions1.R#97:
#> 97: y %>%
#> 98: sapply("g", n = 1)
#> g at functions1.R#114:
#> 114: g(1, y)
#> g at functions1.R#121:
#> 121: g
## print without cli-formatting
print(chk$globals, use_cli = FALSE)
#>
#> ── Unrecognized global functions or variables ──────────────────────────────────
#>
#> <name> <location>
#> %>%() functions1.R#97
#> fAttach2() aaa.R#13
#> fLoad2() functions1.R#156
#> g aaa.R#2 and 13 more...