I would like to keep the glue values as string when assigning to my yaml. Unfortunately, the quotes are not there. Here is some reproducible code:
library(yaml)
library(glue)
begin <- 1970
end <- 2020
yaml <- list(year = glue('between {begin} and {end}'))
yaml_text <- as.yaml(yaml)
cat(as.character(yaml_text), sep = "n", file = "test.yaml", append = TRUE)
Output yaml file:
year: between 1970 and 2020
As you can see there is no string. I would like to have it like this 'year: between 1970 and 2020'
. If we add space to the glue it does return as a string but including the whitespace which is not what I want:
library(yaml)
library(glue)
begin <- 1970
end <- 2020
yaml <- list(year = glue(' between {begin} and {end}')) # white space added
yaml_text <- as.yaml(yaml)
cat(as.character(yaml_text), sep = "n", file = "test.yaml", append = TRUE)
Output:
year: ' between 1970 and 2020'
As you can see it is now in quotes. I don’t understand why. So I was wondering if anyone knows how to get quoted values in a yaml while using glue
?
Recognized by R Language Collective