Description Usage Arguments Details Value
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:
Content after a "#"
Content between single or double quotes
Argument names in function calls: fun(n=3, o=4)
will not warn for 'n' or 'o'
Field names: Identifiers preceded by "$"
Functions that have been explicitly assigned from a package at some place in the script: count <- plyr::count causes all mentions of count to be ignored.
Note that it's not checked WHERE this assignment takes place, nor if it takes place at all (e.g. in a conditional statement)
Functions of class 'standardGeneric', as they are meant to be overwritten.
Note the script still has some difficulties with this, as multiple methods in multiple packages may be defined, only seeming to mask each other
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
1 2 3 4 |
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". |
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. |
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 |
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:
Identifiers with non-standard characters, as the function splits up lines in 'words' by word-boundaries as used by the regular expression ('\b')
Escaped characters may confuse the regexes.
E.g: paste('I wouldn\'t have thought this would cause',duplicateFunction(),'problems, I really didn\'t!') will not trigger an alert, because eveything between paired single quotes is ignored, even though some are escaped.
In this case, the script drops 'I wouldn' and ',duplicateFunction(),' and 't!'.
Or #'s as part of a string, as everything after # is ignored: gsub('#',”,duplicateFunction(text)) passes.
Libraries that have not yet been loaded are not checked! Advise is to specify all needed libraries first, then run 'checkMasking'.
Functions having their own environments may end up calling other functions then those first in the search path. This may cause both false positives and false negatives
If a function is marked .Deprecated
or .Defunct
, an attempt is made to let it pass.
The script looks for the "new" argument in .Deprecated or .Defunct. If there is none, no package is provided, or there is
a replacement with a different name, the script lets it pass. If a package is provided, the script checks whether this package
is higher on the search-list.
And the script of course only allows these functions to be masked, not to mask others.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.