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
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 (pantor/inja#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
Pass as a cpp11::function object
Dynamically generate an inja callback function using inja::Environment::add_callback()
Translate JSON data variables back to R data variables
Evaluate using the cpp11::function object
This 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.
The text was updated successfully, but these errors were encountered: