I am attempting my first Rmarkdown Parameterized report. The first section will download a dataset from one of two sources (and internal vs external database) based on the params 'dataSource' selected by the user. The Rscript/code required is different for the different options.
title: "Optionally DL from external vs internal database"
output: html_document
params:
dataSource:
label: "Select the database for download:"
value: IntD
input: radio
choiceNames: [External DB, Internal DB]
choiceValues: [ExtD, IntD]
inline: TRUE
The following code does work, but is there a way to optionally run an entire Rchunk based on a params selection (some code put directly in the Rchunk header, for example)?
```{r downloadData, include=TRUE}
#Can I run different rchunk or code based on the params$dataSource value??
#Can this be done directly in the Rchunk header?
if(params$dataSource=="IntD"){
source(here::here("R", "Intdownload.R")
}else{
source(here::here("R", "Extdownload.R")
}
```
Other options I've explored (and am working on understanding how to implement) are listed below. Are any of these better options to investigate if download code is likely to be used in other reports/Rscript/Rmarkdown documents? I am a bit confused as to when these might be better than using 'source'?
- creating seperate chunks in an external Rscript and use read_chunk to read in the external script, then call each chunk based on the params option selected.
- Creating a separate Rmarkdown document for datadownload, and then calling that within this Rmarkdown document using child. Does this option essentially allow you to create 2 reports (1 by calling a child Rmarkdown doc, and another for main Rmarkdown document) while using objects created in the child document in the main document?