Loop for output files

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)  {




But I don't know how to put the Rmarkdown code inside a for statement.
Thanks for your time and interest

1 Like

I think you would be interesting by parametrized report.


I let you try and give me feeback here if it works for you. Thanks !

I think I solved It. I don't know if It's the right approach.



#rm(list=setdiff(ls(),c("rx","listar")))  por  rm(list=(ls()))
# en línea 17 del Reporte.Rmd (regional)


for (i in 1:NROW(zone_list=)){

                    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.

This is a good approach the for loop !

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

    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=)) {
                    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 !

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.