I recently saw a function in R where someone had used .
as an argument. I can't seem to find any documentation on this (other than the use of ellipsis or "dot-dot-dot"). Can someone either point me in the direction of documentation or provide an example of usage?
hello.world <- function(.) "Hello World"
# function(.) is what I'm asking about.
A dot in function name can mean any of the following: nothing at all. a separator between method and class in S3 methods. to hide the function name.
The dot you see with the is_spam~. command means that there are no explanatory variables. Typically with model formulas, you will see y~x, but if you have no x variable, y~.
two dots is the second time derivative. so a dot is the same as d/dt. 5.
Periods track the change in the "clock time" between two date-times. They are measured in common time related units: years, months, days, hours, minutes, and seconds. Each unit except for seconds must be expressed in integer values.
Dot is a a valid character in symbol names just like any letter, so .
is no different than let's say a
- it has no special meaning in this context. You can write things like:
> . <- 10
> . + .
[1] 20
It may look strange but is valid in R. The above use function(.)
is let's say unusual, but syntactically valid. Since the author did not reference .
in the function body, we will never know if he meant ...
or just used it because he could.
While the answer given by Simon Urbanek is correct here's a reason the .
is preferred over other characters as a function argument. In some situations, like lapply
a function needs to receive an argument by design. But if there is no need of the argument inside the function we still need a dummy argument name. A .
is the smallest character - almost invisible, so you are not distracted by what the function is delivering. The function(.)
is as good as function()
but has an advantage that it will not give an error when used in apply
family.
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