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
#Argument 'j' after substitute: .Primitive("sqrt")(Sepal.Length)
218
+
## DT[, .Primitive("sqrt")(Sepal.Length)]
219
+
```
220
+
And while `.Primitive("sqrt")(Sepal.Length)` still works, it is almost never the desired form.
221
+
222
+
Even more importantly, if the symbol form is meant to be used, then it can, and should, be used directly in the expression, as there is no need for substitution.
223
+
```{r substitute_fun2, result='hide'}
224
+
DT[, sqrt(Sepal.Length)]
225
+
```
226
+
227
+
If function name to be substituted needs to be namespace-qualified then namespace and function name can be substituted as any other symbol in the expression:
#Argument 'j' after substitute: base::sqrt(Sepal.Length)
231
+
## DT[, base::sqrt(Sepal.Length)]
232
+
```
233
+
207
234
### Substitute variables and character values
208
235
209
236
In the above example, we have seen a convenient feature of `substitute2`: automatic conversion from strings into names/symbols. An obvious question arises: what if we actually want to substitute a parameter with a *character* value, so as to have base R `substitute` behaviour. We provide a mechanism to escape automatic conversion by wrapping the elements into base R `I()` call. The `I` function marks an object as *AsIs*, preventing its arguments from character-to-symbol automatic conversion. (Read the `?AsIs` documentation for more details.) If base R behaviour is desired for the whole `env` argument, then it's best to wrap the whole argument in `I()`. Alternatively, each list element can be wrapped in `I()` individually. Let's explore both cases below.
0 commit comments