The dot has a special meaning within funs. In that context it refers to the dummy parameter. See ?funs for a descrption.
funs constructs a "fun_list" class object which represents a list of functions. Each argument of funs is a function name, character string representing a function name or an expression representing the body of the function. In the last case, within the expression representing the function body, the argument of the function is represented by dot so that . == 5 refers to the function function(.) . == 5 (although dplyr does not actually construct that function but rather uses a "fun_list" object instead).
In this example, mutate_each will run the function once for each column so that this does the same thing as in the question except it also prints out the input each time the constructed function (it is not actually constructed but we can think about it that way) is called:
The dot is used within dplyr mainly (not exclusively) in mutate_each, summarise_each and do. In the first two (and their SE counterparts) it refers to all the columns to which the functions in funs are applied. In do it refers to the (potentially grouped) data.frame so you can reference single columns by using .$xyz to reference a column named "xyz".
The reasons you cannot run
filter(df, . == 5)
is because a) filter is not designed to work with multiple columns like mutate_each for example and b) you would need to use the pipe operator %>% (originally from magrittr).
However, you could use it with a function like rowSums inside filter when combined with the pipe operator %>%:
You should also take a look at the magrittr help files:
Some extract from the help page:
Placing lhs elsewhere in rhs call
Often you will want lhs to the rhs call at another position than the first. For this purpose you can use the dot (.) as placeholder. For example, y %>% f(x, .) is equivalent to f(x, y) and z %>% f(x, y, arg = .) is equivalent to f(x, y, arg = z).
Asked in February 2016Viewed 2,830 timesVoted 14Answered 2 times