Is it possible in R to protect function names (or variables in general) so that they cannot be masked.
I recently spotted that this can be a problem when creating a data frame with the name "new", which masked a function used by lmer and thus stopped it working. (Recovery is easy once you know what the problem is, here "rm(new)" did it.)
A variable name in R programming language can contain numeric and alphabets along with special characters like dot (.) and underline (-). Variable names in R language can begin with an alphabet or the dot symbol. However, if the variable name begins with a dot symbol it should not be a followed by a numeric digit.
A nested function or the enclosing function is a function that is defined within another function. In simpler words, a nested function is a function in another function. There are two ways to create a nested function in the R programming language: Calling a function within another function we created.
Nomenclature of R Variables A valid variable name consists of a combination of alphabets, numbers, dot(.), and underscore(_) characters. Example: var. 1_ is valid. Apart from the dot and underscore operators, no other special character is allowed.
The following rules apply when creating new variables or changing the name of an existing variable: Variable names must be unique in a Dataset. Variable names are up to 64 characters long and can only contain letters, digits and nonpunctuation characters (except that a period (.) is allowed.
There is an easy workaround for your problem, without worrying about protecting variable names (though playing with lockBinding
does look fun). If a function becomes masked, as in your example, it is still possible to call the masked version, with the help of the ::
operator.
In general, the syntax is packagename::variablename
.
(If the function you want has not been exported from the package, then you need three colons instead, :::
. This shouldn't apply in this case however.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With