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

Parameterised books #346

Closed
psychemedia opened this issue Feb 23, 2017 · 6 comments
Closed

Parameterised books #346

psychemedia opened this issue Feb 23, 2017 · 6 comments
Milestone

Comments

@psychemedia
Copy link

psychemedia commented Feb 23, 2017

rmarkdown provides a straightforward way of generating multiple, parameterised reports from a single, base "master report", configured by passing in parameter values from the rmarkdown:render function (RStudio/RMarkdown Parameterized Reports):

rmarkdown::render("MyDocument.Rmd", params = list(
  region = "west"
))

How can a book be generated as compilation of a set of reports? eg something like:

bookdown::render("ParameterisedDocument.Rmd", params = list(
  list(region = "west", otherparameter=1),
  list(region = "east", otherparameter=2)
))

concatenating separate sections of the report from a ParameterisedDocument.Rmd with parameter values list(region = "west", otherparameter=1), for the first part, list(region = "east", otherparameter=2) for the second etc?

What about if I also wanted to top and tail the book with a openingPart.Rmd and a closingPart.Rmd?

i.e. how would I construct something with the sense of:

rmd_files: ["openingPart.Rmd", list(base ="ParameterisedDocument.Rmd", params = list( list(region = "west", otherparameter=1), list(region = "east", otherparameter=2) ) ), "closingPart.Rmd"]

@yihui
Copy link
Member

yihui commented Mar 9, 2017

bookdown::render_book() has a ... argument that is passed to rmarkdown::render(), which means you can certainly pass the params argument there.

For the second question, no, there is not possible (well, it is, but not straightforward).

BTW, I don't know where you got the idea

params = list(
  list(region = "west", otherparameter=1),
  list(region = "east", otherparameter=2)
)

but even with rmarkdown::render(), you cannot pass a list of lists of params. You have to do the explicit loop by youself, and pass one set of params each time.

@yihui yihui added this to the v0.4 milestone Mar 9, 2017
@psychemedia
Copy link
Author

Re: the idea:

params = list(
  list(region = "west", otherparameter=1),
  list(region = "east", otherparameter=2)
)

it was just pseudo-code. My use case is I want a report in book form with an intro, a summary, and then N intermediate chapters which are all generated from the same template but with different parameters.

@yihui yihui closed this as completed Mar 19, 2017
@quantitative-technologies

@psychemedia this is exactly what I want to achieve.

It's the obvious way to report on multiple experiments that only differ in parameters.

@zachary-waller
Copy link

Not sure if anyone is still playnig around with this, but I've made a repository that does this:
https://github.com/zachary-waller/parameterised_bookdown
It's very bare bones, but basically takes the same approach as what bookdown does. I hope it helps someone out!

@psychemedia
Copy link
Author

@zachary-waller This is back in scope for me atm... will check your repo out.

One thing that occurred to me is incrementally adding to a report. Eg you are producing a set of monthly reports as part of an annual report, and want to run the script to add each month to the current report. I guess setting caches up properly may help with that.

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants