Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is purpose of dot before variables (i.e. "variables") in the R Plyr package?

Tags:

r

plyr

What is purpose of dot before variables (i.e. "variables") in the R Plyr package?

for instance, from the R help file:

ddply(.data, .variables, .fun = NULL, ...,
    .progress = "none", .drop = TRUE, .parallel = FALSE)

Any assistance would be greatly appreciated

like image 911
MikeTP Avatar asked Jan 30 '13 16:01

MikeTP


2 Answers

There may be two things going on that are confusing you.

One is the . function in the 'plyr' package. The . function allows you to use a variable as a link rather than referring to the value(s) the variable contains. For instance, in some functions, we want to refer to the object x rather than the value(s) stored in x. In the 'base' package, there is no easy, concise way of doing this, so we use the 'plyr' package to say .(x). The 'plyr' functions themselves use this a lot like so:

ddply(data, .(row_1), summarize, total=sum(row_1))

If we didn't use the . function, 'ddply' would complain, because 'row_1' contains many values, when we really just want to refer to the object.

The other "." in action here is the way people use it as a character in the function arguments' names. I'm not sure what the origin is, but a lot of people seem to do it just to highlight which variables are function arguments and which variables are only part of the function's internal code. The "." is just another character, in this case.

like image 191
Dinre Avatar answered Sep 26 '22 18:09

Dinre


From http://www.jstatsoft.org/v40/i01

Note that all arguments start with . This prevents name clashes with the arguments of the processing function, and helps to visually delineate arguments that control the repetition from arguments that control the individual steps. Some functions in base R use all uppercase argument names for this purpose, but I think this method is easier to type and read.

like image 35
Dieter Menne Avatar answered Sep 24 '22 18:09

Dieter Menne