Open ghost opened 2 years ago
Hi @astronaut-chris - thanks for using jinjar!
Unfortunately, it's not possible to pass an R function to the templating engine like this. The render()
function only accepts R data variables (e.g., scalars, vectors, data frames). You can read more about these constraints here. But I think render()
should give a more helpful error message.
So this means you need to call add_w()
beforehand, and pass the result as a data variable to render()
.
add_w <- function(x){paste0("w", x)}
render("hello {{ name }}", name = add_w("orld"))
In the future, it might be possible to specify functions within the template itself (https://github.com/pantor/inja/issues/238). But this would require a lot of work and there is currently no ETA.
It might be possible to add support for passing functions by
cpp11::function
objectinja::Environment::add_callback()
cpp11::function
objectThis is a very significant change though, so it needs time to get it right. I don't think this would be ready in the short term, but I'll leave this issue open as a feature request.
Thank you for this awesome package.
I am trying to add functions to
...
inrender
, but I don't believe I can. Here is a small reprex:The above throws the error:
Is this not possible with
jinjar
, or should I be doing something differently?Thanks for your help.