I created an RMarkdown file file.Rmd
with parameters.
I know how to access parameters within a r chunk
but not from a bash chunk
If there is absolutely no way to do so, I will write the parameters in a file through r chunk
and then read it from bash chunk
...
---
output: html_document
params:
myParam1:
label: "Choose 1st parameter"
value: 20
input: slider
min: 0
max: 100
myParam2:
label: "Choose 2nd parameter"
value: "Hello"
input: text
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, echo=FALSE}
print(paste("1st parameter :",params$myParam1))
print(paste("2nd parameter :",params$myParam2))
```
```{bash}
# Don't know how to get parameters here
echo $params
```
Thanks
I've seen a few options
Use Sys.setenv
to export variables from R to bash, so add this line to an R chunk.
Sys.setenv(params = params$myParam1)
Use the runr package
To apply the export-to-envirnoment idea from the accepted answer to all params, just add the following do.call
loop to an R chunk before the bash chunk:
```{r, echo=FALSE, message=FALSE}
for (key in names(params)) {
do.call('Sys.setenv', params[key])
}
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With