Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render R markdown from a function

Tags:

r

r-markdown

I need to automate some report generation. I would like to create an rmarkdown report from a function, something like

make_report <- function(file_path = "data_file.txt", outfile){

    # get data from external file
    object <- parse_text(file_path)

    # ?pass it into report template?
    rmarkdown::render("report_template.Rmd", outfile)
}

Where report_template.Rmd prints tables and figures based on the information in the data_frame object. I've seen ways to make rmarkdown templates, but I don't know if there is a way to pass anything into them.

like image 253
gregmacfarlane Avatar asked May 11 '26 00:05

gregmacfarlane


1 Answers

You cannot directly pass objects to render function, but you still can save objects into RDS/csv and load them in your rmarkdown file at the beginning in the hidden section, so it will not be printed to your output document.

like image 172
jangorecki Avatar answered May 12 '26 14:05

jangorecki