Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding parameters modifies logical values #87

Open
dchiu911 opened this issue Sep 14, 2022 · 0 comments
Open

Adding parameters modifies logical values #87

dchiu911 opened this issue Sep 14, 2022 · 0 comments

Comments

@dchiu911
Copy link

I'm trying to create a template _output.yml and then allow the user to add certain parameters. However, this modifies the logical values (e.g. true -> yes) because the initial yaml was created with ymlthis::use_output_yml() and subsequent modification uses yaml::write_yaml(). My modified output_yml object no longer nests the entire yaml under output: so I cannot use ymlthis::use_output_yml(). Is there a more robust way to handle this workflow without calling ymlthis::yml_output() again with all the original parameters?

output_yml <- ymlthis::yml_output(
  .yml = ymlthis::yml_empty(),
  bookdown::gitbook(
    lib_dir = "assets",
    split_by = "chapter",
    config = list(download = "pdf")
  ),
  bookdown::pdf_book(
    keep_tex = TRUE,
    includes = ymlthis::includes2(in_header = "preamble.tex")
  )
)
print(output_yml)
#> ---
#> output:
#>   bookdown::gitbook:
#>     lib_dir: assets
#>     split_by: chapter
#>     config:
#>       download: pdf
#>   bookdown::pdf_book:
#>     keep_tex: true
#>     includes:
#>       in_header: preamble.tex
#> ---
options(ymlthis.remove_blank_line = TRUE)
ymlthis::use_output_yml(.yml = output_yml, path = tempdir(), quiet = TRUE)
options(ymlthis.remove_blank_line = FALSE)
tmpyml <- file.path(tempdir(), "_output.yml")
# The TRUE values are "true"
readLines(tmpyml)
#> [1] "bookdown::gitbook:"          "  lib_dir: assets"          
#> [3] "  split_by: chapter"         "  config:"                  
#> [5] "    download: pdf"           "bookdown::pdf_book:"        
#> [7] "  keep_tex: true"            "  includes:"                
#> [9] "    in_header: preamble.tex"

output_yml <- yaml::read_yaml(tmpyml)
bib_opts <- list(citation_package = "natbib", toc_bib = TRUE)
output_yml[["bookdown::pdf_book"]] <-
  c(output_yml[["bookdown::pdf_book"]], bib_opts)
ymlthis::as_yml(output_yml)
#> ---
#> bookdown::gitbook:
#>   lib_dir: assets
#>   split_by: chapter
#>   config:
#>     download: pdf
#> bookdown::pdf_book:
#>   keep_tex: true
#>   includes:
#>     in_header: preamble.tex
#>   citation_package: natbib
#>   toc_bib: true
#> ---
yaml::write_yaml(x = output_yml, file = tmpyml)
# The TRUE values are "yes"
readLines(tmpyml)
#>  [1] "bookdown::gitbook:"          "  lib_dir: assets"          
#>  [3] "  split_by: chapter"         "  config:"                  
#>  [5] "    download: pdf"           "bookdown::pdf_book:"        
#>  [7] "  keep_tex: yes"             "  includes:"                
#>  [9] "    in_header: preamble.tex" "  citation_package: natbib" 
#> [11] "  toc_bib: yes"

Created on 2022-09-14 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant