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
{# this works #}
{% if 1 == 1 %}
{{ variable }}
{% endif %}
{# this does NOT work #}
{% if variable == 'test' %}
{{ variable }}
{% endif %}
Error
Error in `render()`:
! Problem encountered while rendering template.
Caused by error:
! Variable 'test' not found.
ℹ Error occurred on line 7 and column 20.
Run `rlang::last_trace()` to see where the error occurred.
Session information
R version 4.3.1 (2023-06-16)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.5
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/Los_Angeles
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] jinjar_0.3.1 jsonlite_1.8.7
loaded via a namespace (and not attached):
[1] utf8_1.2.4 R6_2.5.1 xfun_0.41 tidyselect_1.2.0 magrittr_2.0.3 glue_1.6.2 tibble_3.2.1 knitr_1.45
[9] pkgconfig_2.0.3 dplyr_1.1.3 generics_0.1.3 lifecycle_1.0.3 cli_3.6.1 fansi_1.0.5 vctrs_0.6.4 DBI_1.1.3
[17] compiler_4.3.1 rstudioapi_0.15.0 tools_4.3.1 pillar_1.9.0 fs_1.6.3 rlang_1.1.1
The text was updated successfully, but these errors were encountered:
This error is caused by the right-hand side of the comparison. The template syntax only supports string literals specified using double-quotes (not single-quotes). This is an unfortunate consequence of the underlying usage of JSON objects.
In your example, you should use "test" instead of 'test'. Here's a quick demo:
library(jinjar)
render("{{ x == 'test' }}", x="test")
#> Error in `render()` at jinjar/R/render.R:44:2:#> ! Problem encountered while rendering template.#> Caused by error:#> ! Variable 'test' not found.#> ℹ Error occurred on line 1 and column 10.
render('{{ x == "test" }}', x="test")
#> [1] "true"
davidchall
changed the title
Variable comparison inside template throws "Variable not found" error
String literal with single-quotes throws "Variable not found" error
Nov 10, 2023
davidchall
changed the title
String literal with single-quotes throws "Variable not found" error
String literal with single-quotes causes error "Variable not found"
Nov 10, 2023
Variable comparison inside a template throws an error. Below is a reproducible example.
R code
Template file template.txt
Error
Session information
The text was updated successfully, but these errors were encountered: