From 698c557dfe77d93e1d0c86da49853573b5c652de Mon Sep 17 00:00:00 2001 From: Jan Gorecki Date: Fri, 8 May 2026 17:34:55 +0200 Subject: [PATCH 1/2] extend description of an issue from the past --- vignettes/datatable-programming.Rmd | 38 ++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/vignettes/datatable-programming.Rmd b/vignettes/datatable-programming.Rmd index 30c2478a8..5d37ded34 100644 --- a/vignettes/datatable-programming.Rmd +++ b/vignettes/datatable-programming.Rmd @@ -397,7 +397,43 @@ print(j) DT[, j, env = list(j = j)] ``` -### Common mistakes +### Good practices + +When using meta-programming interfaces, not only data.table `env` argument, user is also in control of how call stack will look like. We control what will go into errors call stack, or extra call stack reporting routines. It is either reference to named function or it an anonymous function. + +```{r report_from_where_and_add_one, eval = FALSE} +report_from_where_and_add_one = function(x) { + print(sys.calls()) + invisible(x + 1L) +} +do.call(report_from_where_and_add_one, list(x = 1L)) +# [[1]] +# do.call(report_from_where_and_add_one, list(x = 1L)) + +# [[2]] +# (function(x) { +# print(sys.calls()) +# x + 1L +# })(x = 1L) +do.call("report_from_where_and_add_one", list(x = 1L)) +# [[1]] +# do.call("report_from_where_and_add_one", list(x = 1L)) + +# [[2]] +# report_from_where_and_add_one(x = 1L) +``` + +```{r raise_exception, eval = FALSE} +raise_exception = function(x) { + stop("a1") +} +do.call(raise_exception, list(x = 1L)) +# Error in (function (x) : a1 +do.call("raise_exception", list(x = 1L)) +# Error in raise_exception(x = 1L) : a1 +``` + +And data.table use case... It is important to understand the difference between passing an object and a name that points to an object. See the verbose output of following examples. From 3d20b813a1b71bba88bc5fc2b2a1eff1bcc80fd3 Mon Sep 17 00:00:00 2001 From: Jan Gorecki Date: Mon, 11 May 2026 14:59:46 +0200 Subject: [PATCH 2/2] Update vignettes/datatable-programming.Rmd Co-authored-by: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com> --- vignettes/datatable-programming.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/datatable-programming.Rmd b/vignettes/datatable-programming.Rmd index 5d37ded34..55f151184 100644 --- a/vignettes/datatable-programming.Rmd +++ b/vignettes/datatable-programming.Rmd @@ -399,7 +399,7 @@ DT[, j, env = list(j = j)] ### Good practices -When using meta-programming interfaces, not only data.table `env` argument, user is also in control of how call stack will look like. We control what will go into errors call stack, or extra call stack reporting routines. It is either reference to named function or it an anonymous function. +When using meta-programming interfaces, not only data.table's `env` argument, the user is also in control of how the call stack will look like. This affects what appears in error messages and other call stack reportings. The call target is either a named function or an anonymous function. ```{r report_from_where_and_add_one, eval = FALSE} report_from_where_and_add_one = function(x) {