Pipeline to run all RMarkdown Files in sequence

Is there a way to create a pipeline to run multiple .Rmd files like we do for .R scripts files.

#Pipeline using .R scripts runs smoothly all at once in the sequence provided
source("Src/Script_File_1.R")
source("Src/Script_File_2.R")

#But using Pipeline similarly for .Rmd scripts doesn't run and produces errors
source("Src/Script_File_1.Rmd")
source("Src/Script_File_2.Rmd")

# Error:
Error in source("Src/Script_File_1.Rmd") : 
  attempt to use zero-length variable name

If you are using any specific method, please let me know. I would like to breakdown my code into different files. I do prefer .Rmd files over .R files for clarity. So, any help would be appreciated.

Thanks for your help!

Hi @ksingh19,
Does this do what you require? The purl() function extracts the R code from the .Rmd file, then that can then be sourced.

library(knitr)
source(knitr::purl("file_one.Rmd"))
source(knitr::purl("file_two.Rmd"))

See:
https://bookdown.org/yihui/rmarkdown-cookbook/purl.html

Perfect! It does work :smiley:
Thank you so much @DavoWW!

@DavoWW! It works perfectly in terms of results or outputs. But I also noticed that it displays .R script files (file_one.R and file_two.R). This means if we have several files, all will be seen in the folder. Is there a way that it works but doesn't display these extra .R files. I tried to get this information from the documentation provided. But I am sure I am missing something here.

Thanks for your help again!

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.