Skip to content

Commit 33b60cc

Browse files
correct last example by using symbol
1 parent 57f5baf commit 33b60cc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

man/groupingsets.Rd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ groupingsets(DT, jj = quote(list(count = .N, total = sum(value))),
9797
9898
# Example showing when substitute() is necessary - in a wrapper function
9999
# Note: Use substitute(expr, list(param=value)) to bind values, not symbols
100-
custom_grouping <- function(DT, multiplier = 1) {
100+
custom_grouping <- function(DT, multiplier) {
101101
# use substitute() with environment to ensure variable are properly evaluated
102-
groupingsets(DT, jj = substitute(list(count = .N, total = sum(value) * multiplier),
103-
list(multiplier = multiplier)),
102+
groupingsets(DT, jj = substitute(list(count = .N, total = sum(value) * m),
103+
list(m = multiplier)),
104104
by = c("color", "year", "status"),
105105
sets = list("color", c("year", "status"), character()), id = TRUE)
106106
}
107107
# Using the wrapper function
108-
custom_grouping(DT, multiplier = 2)
108+
local({ foo <- 3; custom_grouping(DT, multiplier = foo) })
109109
}
110110
\keyword{ data }

0 commit comments

Comments
 (0)