A period in a function name can mean any of the following:
- nothing at all
- separator between method and class in S3 methods
- to hide the function name
Possible Values
1. Nothing at all
A point in data.frame does not separate data from frame , except visually.
2. Separation of methods and classes in S3 methods
plot is one example of the general S3 method. Thus, plot.lm and plot.glm are the basic definitions of functions that are used when calling plot(lm(...)) or plot(glm(...))
3. To hide internal functions
When writing packages, it is sometimes useful to use leading points in function names, since these functions are somewhat hidden from the general view. Functions that should be purely internal to the package sometimes use this.
In this context, โsomewhat hiddenโ simply means that a variable (or function) is usually not displayed when you specify an object using ls() . To make ls show these variables, use ls(all.names=TRUE) . Using a dot as the first letter of a variable, you change the scope of the variable itself. For example:
x <- 3 .x <- 4 ls() [1] "x" ls(all.names=TRUE) [1] ".x" "x" x [1] 3 .x [1] 4
4. Other possible causes
In the Hadley plyr package, it uses convention to use leading points in function names. It is like a mechanism to try to ensure that when resolving variable names, values โโare resolved to user variables, and not to internal function variables.
Complications
This mess of different uses can lead to very confusing situations, because these different applications can be implicated in the same function name.
For example, to convert a data.frame to a list, you use as.list(..)
as.list(iris)
In this case, as.list is a common S3 method, and you pass data.frame . So the S3 function is called as.list.data.frame :
> as.list.data.frame function (x, ...) { x <- unclass(x) attr(x, "row.names") <- NULL x } <environment: namespace:base>
And for something really impressive, download the data.table package and look at the as.data.table.data.frame function:
> library(data.table) > methods(as.data.table) [1] as.data.table.data.frame* as.data.table.data.table* as.data.table.matrix* Non-visible functions are asterisked > data.table:::as.data.table.data.frame function (x, keep.rownames = FALSE) { if (keep.rownames) return(data.table(rn = rownames(x), x, keep.rownames = FALSE)) attr(x, "row.names") = .set_row_names(nrow(x)) class(x) = c("data.table", "data.frame") x } <environment: namespace:data.table>