A block like new_head_block() is expected to return an expression of the
form utils::head(data, n = 10L), which will then be evaluated in an
environment where he have a name data bound to some dataset. In order to
perform some manipulations of such block expressions it is required to
somehow mark the terms that correspond to input data and for that we can
use the syntax introduced by base::bquote(). What we would prefer to have
as block expression therefore is not the above, but something like
utils::head(.(data), n = 10L), as this affords us more possibilities for
performing substitutions (and therefore generates cleaner code).
In order to interpolate certain arguments in a first step, we unfortunately
cannot use base::bquote(), but we can use bbquote() instead to generate
the desired expression.
bquote(utils::head(.(data), n = .(n)), list(n = 10L))
#> Error in eval(e[[2L]], where) : object 'data' not found
bbquote(utils::head(.(data), n = .(n)), list(n = 10L))
#> utils::head(.(data), n = 10L)
This also works with ..() and splicing.