Some common R functions have argument names that end with a single dot.
For example, the warning() function shows the following in the usage section when looking at the documentation with ?warning:
warning(..., call. = TRUE, immediate. = FALSE, noBreaks. = FALSE,
domain = NULL)
With the exception of "domain", all of the arguments with names have names that end in dots.
Similarly, the default prcomp() function from the 'stats' library shows the following in its usage instructions:
prcomp(x, retx = TRUE, center = TRUE, scale. = FALSE,
tol = NULL, rank. = NULL, ...)
The arguments "scale." and "rank." end with a dot, and all of the others do not. It seems particularly weird that "scale." ends with a dot but "center" does not.
I know a dot is a permitted character in a variable name with R, and that I could name a variable this.variable.name.is.full.of.dots.
if I wanted to - but since the dot being the last character in the names of certain function arguments seems to be a recurring theme in common R functions, does this have a special meaning?
CodePudding user response:
Unless we have commit messages or a naming convention, we can only guess. And I suspect this is very old code, possibly even preceding R.
Looking at the source code of warning
we can notice three facts:
The code creates an object
call
but usescall.
later on. So the trailing dot prevents a name collision and avoids having to come up with a fitting name other thancall
.All parameters passed to the
.Internal
call towarning
have the trailing dot, which makes it easier to keep track and distinguish them from other parameters.It has
...
as a parameter and it is not impossible that someone might want to dowarning(message = "The call was: ", call = "f(x)")
for clarity. (I don't think this was the main consideration.)
Looking at the source code of prcomp
, I suspect naming is intended to make it easier to distinguish the parameters from the scale
and rank
functions or ensure that the functions are not used instead of the parameters if the parameters are missing.
CodePudding user response:
Basically it means "nothing special". In the case of call.
it's probably because the authors didn't want to have confusion of the parameter name with the name of a base R function by the name of call
. In the case of the other it might be for consistency with the first naming choice as well as trying to make them sufficiently unusual that they would not be confused with other. The "dot" is just a character. There no semmantic reason for choosing those names. The is a slightly semantic justification for a leading period. Functions whose name start with a period get handled differently by a few other functions, such as the ls
function.