R/quote.r
quoted.RdThis function is similar to ~ in that it is used to
capture the name of variables, not their current value. This is used
throughout plyr to specify the names of variables (or more complicated
expressions).
.(..., .env = parent.frame())list of symbol and language primitives
Similar tricks can be performed with substitute, but when
functions can be called in multiple ways it becomes increasingly tricky
to ensure that the values are extracted from the correct frame. Substitute
tricks also make it difficult to program against the functions that use
them, while the quoted class provides
as.quoted.character to convert strings to the appropriate
data structure.
.(a, b, c)
#> List of 3
#> $ a: symbol a
#> $ b: symbol b
#> $ c: symbol c
#> - attr(*, "env")=<environment: 0x63d681dc3230>
#> - attr(*, "class")= chr "quoted"
.(first = a, second = b, third = c)
#> List of 3
#> $ first : symbol a
#> $ second: symbol b
#> $ third : symbol c
#> - attr(*, "env")=<environment: 0x63d681dc3230>
#> - attr(*, "class")= chr "quoted"
.(a ^ 2, b - d, log(c))
#> List of 3
#> $ a^2 : language a^2
#> $ b - d : language b - d
#> $ log(c): language log(c)
#> - attr(*, "env")=<environment: 0x63d681dc3230>
#> - attr(*, "class")= chr "quoted"
as.quoted(~ a + b + c)
#> List of 3
#> $ a: symbol a
#> $ b: symbol b
#> $ c: symbol c
#> - attr(*, "env")=<environment: 0x63d681dc3230>
#> - attr(*, "class")= chr "quoted"
as.quoted(a ~ b + c)
#> List of 3
#> $ a: symbol a
#> $ b: symbol b
#> $ c: symbol c
#> - attr(*, "env")=<environment: 0x63d681dc3230>
#> - attr(*, "class")= chr "quoted"
as.quoted(c("a", "b", "c"))
#> List of 3
#> $ a: symbol a
#> $ b: symbol b
#> $ c: symbol c
#> - attr(*, "env")=<environment: 0x63d681dc3230>
#> - attr(*, "class")= chr "quoted"
# Some examples using ddply - look at the column names
ddply(mtcars, "cyl", each(nrow, ncol))
#> cyl nrow ncol
#> 1 4 11 11
#> 2 6 7 11
#> 3 8 14 11
ddply(mtcars, ~ cyl, each(nrow, ncol))
#> cyl nrow ncol
#> 1 4 11 11
#> 2 6 7 11
#> 3 8 14 11
ddply(mtcars, .(cyl), each(nrow, ncol))
#> cyl nrow ncol
#> 1 4 11 11
#> 2 6 7 11
#> 3 8 14 11
ddply(mtcars, .(log(cyl)), each(nrow, ncol))
#> log(cyl) nrow ncol
#> 1 1.386294 11 11
#> 2 1.791759 7 11
#> 3 2.079442 14 11
ddply(mtcars, .(logcyl = log(cyl)), each(nrow, ncol))
#> logcyl nrow ncol
#> 1 1.386294 11 11
#> 2 1.791759 7 11
#> 3 2.079442 14 11
ddply(mtcars, .(vs + am), each(nrow, ncol))
#> vs + am nrow ncol
#> 1 0 12 11
#> 2 1 13 11
#> 3 2 7 11
ddply(mtcars, .(vsam = vs + am), each(nrow, ncol))
#> vsam nrow ncol
#> 1 0 12 11
#> 2 1 13 11
#> 3 2 7 11