This function captures the current context, making it easier
to use **ply
with functions that do special evaluation and
need access to the environment where ddply was called from.
here(f)
f | a function that does non-standard evaluation |
---|
df <- data.frame(a = rep(c("a","b"), each = 10), b = 1:20) f1 <- function(label) { ddply(df, "a", mutate, label = paste(label, b)) } if (FALSE) f1("name:") # Doesn't work because mutate can't find label in the current scope f2 <- function(label) { ddply(df, "a", here(mutate), label = paste(label, b)) } f2("name:")#> a b label #> 1 a 1 name: 1 #> 2 a 2 name: 2 #> 3 a 3 name: 3 #> 4 a 4 name: 4 #> 5 a 5 name: 5 #> 6 a 6 name: 6 #> 7 a 7 name: 7 #> 8 a 8 name: 8 #> 9 a 9 name: 9 #> 10 a 10 name: 10 #> 11 b 11 name: 11 #> 12 b 12 name: 12 #> 13 b 13 name: 13 #> 14 b 14 name: 14 #> 15 b 15 name: 15 #> 16 b 16 name: 16 #> 17 b 17 name: 17 #> 18 b 18 name: 18 #> 19 b 19 name: 19 #> 20 b 20 name: 20# Works :)