Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
The recent(ish) advent of parameters in rmarkdown reports is pretty nifty but there’s a little bit of behaviour that can come in handy but doesn’t come across in the documentation. You can use table parameters for rmarkdown reports.
Previously, if you wanted to produce multiple reports based off a dataset, you would make the dataset available and then perform filtering in the report. Now we can pass the filtered data directly to the report, which keeps all the filtering logic in one place.
It’s actually super simple to add table parameters for rmarkdown reports.
View the code on Gist.
We specify a params
section and we create a parameter for our table. I use the !r iris
bit to add default contents to the report so that I can generate the report easily.
With this fragment now, I could easily pass in a new dataset to this report.
rmarkdown::render("MWE.Rmd", params = list(mytbl=mtcars))
By being able to pass in tables to the report in the params
argument directly, any filtering logic can now be kept external to the report and kept close to the iterator. This is pretty darn cool in my opinion!
The post R Quick Tip: Table parameters for rmarkdown reports appeared first on Locke Data. Locke Data are a data science consultancy aimed at helping organisations get ready and get started with data science.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.