Escape Special Character in output-path of rmarkdown::render()

Viewed 79

I'm currently working on multiple reports that I generate with rmarkdown::render(). I use a Main.Rmd as a template to create the report for a certain group. In an R.Script-File I use a loop to iterate over the groups (and their subgroups) and render an individual report. My loop looks like this:

for(i in 1:length(mygroupfile)) {
   
    act.group = list(mygroupfile[[i]])
    save(act.group,file="actgroup.RData")
    
    rmarkdown::render("Main.Rmd",
        output_format=pdf_document(),
        output_file=paste0("Group ",act.group[[1]][[8]],".pdf"),
        output_dir=path)

}

So my groups are organized in a list of lists, each list contains specific group information (e.g. subgroups, subsubgroups, name of the main group as a string, etc...). So in the example above act.group[[1]][[8]] stands for the main group name. The actual group is saved as an object (.Rdata) so I can use it within the Main-file and its subfiles/classes (e.g. R-Script generating all plots).

Unfortunately, the path I'm using for storing the reports (output_dir=path) contains a special character ("&"). More unfortunately, I cannot avoid using this path because it's the department name that contains the character...

I tried to escape it with a backslash or use paste(), sprintf(), file.path(), cat() but nothing works. I always get an error using this path... I tried it with a local path on my PC - that works...

I'm working in a Windows environment (Windows 10).

I hope someone can help me?

Thanks!!

0 Answers
Related