Skip to content

Commit 74f0da4

Browse files
nitish jhanitish jha
authored andcommitted
updated doc of env
1 parent bad266b commit 74f0da4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

man/data.table.Rd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ data.table(\dots, keep.rownames=FALSE, check.names=FALSE, key=NULL, stringsAsFac
177177
See examples as well as \href{../doc/datatable-secondary-indices-and-auto-indexing.html}{\code{vignette("datatable-secondary-indices-and-auto-indexing")}}.
178178
}
179179
180-
\item{env}{ List or an environment, passed to \code{\link{substitute2}} for substitution of parameters in \code{i}, \code{j} and \code{by} (or \code{keyby}). Use \code{verbose} to preview constructed expressions. For more details see \href{../doc/datatable-programming.html}{\code{vignette("datatable-programming")}}. }
180+
\item{env}{ List or an environment, passed to \code{\link{substitute2}} for substitution of parameters in \code{i}, \code{j} and \code{by} (or \code{keyby}). For function names, you can use them as strings (e.g., \code{"sum"}) or pass function objects directly (e.g., \code{sum}). Use \code{verbose} to preview constructed expressions. For more details, see \href{../doc/datatable-programming.html}{\code{vignette("datatable-programming")}}.}
181181
182182
\item{showProgress}{ \code{TRUE} shows progress indicator with estimated time to completion for lengthy "by" operations. }
183183
}
@@ -403,6 +403,15 @@ print(DT["b", v2:=84L, on="x"]) # subassign to new column by reference (NA
403403

404404
DT[, m:=mean(v), by=x][] # add new column by reference by group
405405
# NB: postfix [] is shortcut to print()
406+
407+
# Injecting function into env parameter
408+
DT <- data.table(a = rep(1:2, each = 5), b = 1:10)
409+
410+
DT[, f(b), by = a, env = list(f = "sum")] # Use function name as a string
411+
DT[, f(b), by = a, env = list(f = "sum"), verbose = TRUE] # Preview function name injection
412+
DT[, f(b), by = a, env = list(f = sum)] # Use function object directly
413+
DT[, f(b), by = a, env = list(f = sum), verbose = TRUE] # Preview function object injection
414+
406415
# advanced usage
407416
DT = data.table(x=rep(c("b","a","c"),each=3), v=c(1,1,1,2,2,1,1,2,2), y=c(1,3,6), a=1:9, b=9:1)
408417

0 commit comments

Comments
 (0)