Hello,
I don't know how to perform a loop in order to produce many reports (html).
I assign the same code in my Rmarkdown, but I need to specify a value in order to filter data and produce the html files. It's a simple but annoying to edit 10 times the rx. I was thinking in something as:
for (rx 1:10) {
Rmakdown
outputname_rx
}
But I don't know how to put the Rmarkdown code inside a for statement.
Thanks for your time and interest
I think I solved It. I don't know if It's the right approach.
library(knitr)
library(markdown)
library(rmarkdown)
zone_list=c(4,5,13,8,9)
#rm(list=setdiff(ls(),c("rx","listar"))) por rm(list=(ls()))
# en línea 17 del Reporte.Rmd (regional)
rm(list=setdiff(ls(),c("rx","zone_list")))
for (i in 1:NROW(zone_list=)){
rx=listar[i]
rmarkdown::render('/home/juan/Documents/recolectores/Reporte.Rmd',
output_file = paste("Reporte_",zone_list=i], ".html", sep=''))
}
I run this and works fine. But really, maybe It's a bit dirty.
Thanks for your replies.
Is rx an object you use inside your Rmd document ?
If so, currently it works because by default render has access to the value of the parent frame. Another approach would be to use it as a param in the Rmd file.
You yaml header would contain
params:
rx: <default value>
and use params$rx in place of rx in your doc.
and it you call you would do
for (i in 1:NROW(zone_list=)) {
rmarkdown::render('/home/juan/Documents/recolectores/Reporte.Rmd',
output_file = paste0("Reporte_", zone_list[i], ".html"),
param = list(rx = listar[i]))
}
Parametrized report are really powerful has they allow you to get different type of outputs based on one source file. If you use product like RStudio Connect, this would be the way to go.
Anyway, your solution is completly fine ! Well done !