Skip to content

Commit 26b84b1

Browse files
committed
extend env vignette for common trap, closes #6031
1 parent e25ea80 commit 26b84b1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

vignettes/datatable-programming.Rmd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,19 @@ print(j)
376376
DT[, j, env = list(j = j)]
377377
```
378378

379+
### Common mistakes
380+
381+
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.
382+
383+
```{r obj_vs_objname}
384+
DT[, fun(Petal.Width), env = list(fun = mean), verbose=TRUE]
385+
DT[, fun(Petal.Width), env = list(fun = "mean"), verbose=TRUE]
386+
```
387+
388+
User will usually want to substitute function name rather than function body.
389+
390+
In case of any doubts on the `env` interface functioning user is advised to look at `verbose` output.
391+
379392
## Retired interfaces
380393

381394
In `[.data.table`, it is also possible to use other mechanisms for variable substitution or for passing quoted expressions. These include `get` and `mget` for inline injection of variables by providing their names as strings, and `eval` that tells `[.data.table` that the expression we passed into an argument is a quoted expression and that it should be handled differently. Those interfaces should now be considered retired and we recommend using the new `env` argument, instead.

0 commit comments

Comments
 (0)