The YAML header allows us to set parameters using the params and choices variables. However, it seems that we can only choose one value from the choices list. Is there a way to select multiple (and hence to have a multi-item vector parameter)? For example, in each analysis report, I would like to compare two fruits (apple vs orange, apple vs pear, etc).
Since I don't know of a way to multi-select from choices, I tried:
But I got this error " The following parameters cannot be customized: fruits". So I don't even get the choices list to choose from. But it actually works for the default value if I ignore the error and click "Knit".
I haven't used the choices option, but couldn't you pass a vector of two values as a single parameter? For example, to knit an rmarkdown file for every pair of fruits you could do:
Thanks @joels! This will not output the user interface to choose, but most of the time I run all combinations anyway. So this will be very helpful. I tried it out, but got a "Error: pandoc document conversion failed with error 1". It's a separate question (perhaps some pandoc setting?), but thought you maybe able to point out the issue. Here is the output when running the knit:
R-3.5.1> map(combn(x, 2, simplify=FALSE),
+ ~ render(input="<full_path>/test_markdown3.Rmd",
+ output_file = paste("test", .x, ".html"),
+ params=list(fruits=.x)))
processing file: test_markdown3.Rmd
|............. | 20%
inline R code fragments
|.......................... | 40%
label: setup (with options)
List of 5
$ include: symbol F
$ echo : logi FALSE
$ results: chr "hide"
$ message: logi FALSE
$ warning: logi FALSE
|....................................... | 60%
ordinary text without R code
|.................................................... | 80%
label: unnamed-chunk-1
|.................................................................| 100%
ordinary text without R code
output file: test_markdown3.knit.md
/<some_path>/apps/pandoc/1.19.2.1-goolf-1.7.20/bin/pandoc +RTS -K512m -RTS test_markdown3.utf8.md --to html4 --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc2f01f5c4dacfa.html pandoc2f01f29532b9d.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template /<some_path>/apps/R/3.5.1-goolf-1.7.20/lib64/R/library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable 'theme:bootstrap' --include-in-header /tmp/RtmpCNYbIW/rmarkdown-str2f01f2ce20a4c.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --variable code_folding=hide --variable code_menu=1
pandoc: pandoc2f01f29532b9d.html: openFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 1
In addition: Warning message:
In if (nzchar(file_ext)) paste(".", file_ext, sep = "") else "" :
the condition has length > 1 and only the first element will be used
Note that I do need to put in the full path of the rmarkdown file even though they are in the same path. Not sure why. Also, what does the "." in ".x" mean?
Thanks!
I'm not sure what specifically is going wrong. Could you post a self-contained reproducible example (i.e., a minimal rmarkdown document and perhaps a small data sample, if necessary (though you could probably build the data sample into the rmarkdown document), that I can run on my machine and that reproduces the error you're getting?
The .x is a "pronoun" that refers back to the first argument of map (combn(x, 2, simplify=FALSE), which is the list we're iterating over. Each .x is one of the elements of combn(x, 2, simplify=FALSE)). Also, in case it was confusing, the x and the .x have nothing to do with each other. I should have called the x vector fruits or something like that to avoid confusion. See the help for map for more details on the .x argument.
Thanks again. The function with map combinations have been working very well. I just want to add the manual option with the "Knit with Parameters" option (in the Knit pull down) here. I found that there is "input: select" and "multiple: yes" setting options in YAML header (see below). It can be handy when we just want to test one set of combination.
When clicking "Knit with Parameters", an input dialog window will pop up and allow to select multiple choices (see screenshot). It captures then as a vector of strings (fruits).