逃避rmarkDown :: Render()输出路径中的特殊特征

发布于 2025-01-31 17:26:35 字数 895 浏览 2 评论 0原文

我目前正在研究与RmarkDown :: Render()一起生成的多个报告。 我使用main.rmd作为模板来为某个组创建报告。 在R.Script文件中,我使用一个循环在各组(及其子组)上迭代并渲染单个报告。我的循环看起来像这样:

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)

}

因此我的组在列表中组织了,每个列表包含特定的组信息(例如子组,子组,主组的名称为字符串等等等...)。因此,在上面的示例中。组[[1]] [[8]]代表主要组名称。实际组被保存为对象(.rdata),因此我可以在主文件及其子文件/类中使用它(例如R-Script生成所有图)。

不幸的是,我正在使用路径用于存储报告(output_dir = path)包含一个特殊字符(“&”)。更遗憾的是,我无法避免使用此路径,因为它是包含角色的部门名称...

我尝试用后斜切或使用paste(),sprintf(),file.path( ),cat(),但没有什么可用。使用此路径我总是会出现错误...我尝试使用PC上的本地路径尝试 - 它

在Windows环境中工作(Windows 10)。

我希望有人可以帮助我吗?

谢谢!!

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!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文