checkMasking: Check for possible masking problems in saved .R-files

Description Usage Arguments Details Value

View source: R/Misc.R

Description

When loading libraries, the function library warns if functions are masked, but it's often not clear if these functions are used in a script.
This function reads the files named in "scripts" as texfiles, and scans for function-names that have possibly been masked, and returns a list of potential problems, along with line numbers./cr Call this script after all relevant libraries have been loaded.
It's not perfect, as the pattern matching to decide what is potentially a function-call and what is not is problematic
Excluded are:

Furthermore, you can specify names that can be ignored (e.g. the name 'n' from dplyr::n gives lots of false positives if you assign n in .GlobalEnv)
See also 'allowed' in the arguments Checking only takes place for functions, not for data-objects

Usage

1
2
3
4
checkMasking(scripts = c(),
  allowed = getOption("checkMasking_Allowed"),
  extrascripts = c(getOption("checkMasking_extraScripts")),
  functions = c(), packages = c("own"))

Arguments

scripts

A character vector with filenames to check

allowed

A data.frame with often used functions, along with the package you intend to use with that, or "any".
Names in this data.frame are ignored in any scripts. Instead, if an environment is specified, the functions checks whether these names are not masked from the given environment.
For examples, you can look at getOption('checkMasking_Allowed'), the default value. If this option is unset when loading this library, it is set to some standard value, you can use these values as example.

extrascripts

Another character vector with filenames, appended to scripts. The reason there are 2 is in order to specify your own script, to go along with standardscripts.
The value 'self' is treated differently: it tells the script to extract its own source code. This may fail if it is not available, in this case try install.packages(..., type='source') or options(keep.source=TRUE)

functions

list of functions or function names for which source code should be checked.

packages

list of packages for which all functions should be checked

Details

This function makes use of the global options "checkMasking_Allowed" and checkMasking_extraScripts:
See for information regarding checkMasking_Allowed at the "allowed" parameter.
If this library is loaded, and this option is unset, it is set to a default value.
If you don't want any values to be allowed, use options(checkMasking_Allowed=”)
The option checkMasking_extraScripts is useful if you have some code that is used over and over.
If you want to check function from all loaded libraries, you can use
checkMasking(packages=search())#'

This function may fail to notice problems if it doens't recognize function-names well. Some pitfalls are:

Value

0 (invisibly) if no potentional problems have been found, otherwise a nested list with information.
The exact structure of the return may be changed in future versions, so is not meant to be automatically processed,
except for the check for a return of 0 for "no problems"
Right now, the structure is a list with elements for each script that has been processed (empty if no problems were found in that particular script, but if there were problems in other scripts)
These elements are list, with elements for each line with a problem, being character vectors with a line number, the contents of that line, and the name that triggered it's potential problem.


EmilBode/EmilMisc documentation built on Feb. 24, 2020, 4:11 p.m.