You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See examples as well as \href{../doc/datatable-secondary-indices-and-auto-indexing.html}{\code{vignette("datatable-secondary-indices-and-auto-indexing")}}.
178
178
}
179
179
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")}}.}
181
181
182
182
\item{showProgress}{ \code{TRUE} shows progress indicator with estimated time to completion for lengthy "by" operations. }
183
183
}
@@ -403,6 +403,15 @@ print(DT["b", v2:=84L, on="x"]) # subassign to new column by reference (NA
403
403
404
404
DT[, m:=mean(v), by=x][] # add new column by reference by group
405
405
# 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
0 commit comments