Closed brshallo closed 2 years ago
I'm afraid that I can't do much about it. The output is generated from yaml::as.yaml
(), which doesn't provide an option to write out arrays using the []
syntax.
Usually probably doesn't really matter except in cases like #647 when are dynamically generating tags.
That's true. In case of #647, you may want the function to call paste(..., collapse = '"\n "')
instead, and use the bullet syntax for the array:
tags:
- "`r your_func()`"
Regarding this
The output is generated from yaml::as.yaml(), which doesn't provide an option to write out arrays using the [] syntax.
Supporting this is still a feature request https://github.com/vubiostat/r-yaml/issues/77
That's true. In case of #647, you may want the function to call
paste(..., collapse = '"\n "')
instead, and use the bullet syntax for the array:
@yihui per conversation at #647 / associated SO thread I thought programmatically passing arguments in here required using an array syntax (rather than bulleted)...?
For example this (and iterations on it that I tried) error:
tags:
- "`r paste(head(letters), collapse = '"\n - "')`"
#> Error in yaml::yaml.load(..., eval.expr = TRUE) :
#> Parser error: while parsing a block collection at line 7, column 3 did not find expected '-' indicator at line 7, column 43
#> Calls: local ... parse_yaml_front_matter -> yaml_load -> <Anonymous>
#> Execution halted
#> Error: Failed to render content/post/2022-05-12-test-post/index.Rmd
#> Execution halted
@brshallo I'm not sure how to explain this hack born out of the constraints of both valid YAML syntax and valid R code:
tags:
- '`r paste(head(letters), collapse = "\u27\n - \u27")`'
but I think it should work. If you really need me to explain, I can surely try. If you wrap the hack into a function, you wouldn't need so much hack (i.e., paste(..., collapse = '"\n "')
should just work).
Thanks @yihui, paste(..., collapse = '"\n - "')
wrapped in the function works perfectly! Hadn't expected that to make a difference -- no need to explain 😊.
Feel free to close for my needs. (Unless wanting to keep open until the r-yaml issue mentioned above is resolved.)
For the purposes of #647 / https://github.com/brshallo/funspotr/issues/8 I have spot_tags()
default to first read-in the file and do a rough check on whether the function is used in either a bulleted or array format and then it sets collapse
accordingly.
Great! Thanks for the update!
For example will change:
To:
Usually probably doesn't really matter except in cases like #647 when are dynamically generating tags.