r - 将 Rmarkdown 渲染到 R 包外的目录
问题描述
我有一个生成 RMarkdown html 报告的 R 包。.Rmd 文件位于系统库/包目录中。我想创建一个函数htmlreport()
来将 html 报告保存到指定的输出目录路径。如果output_path
未指定,该功能应该可以浏览到输出文件夹。
渲染后我还想打开生成的 html 报告。
我不知道该怎么做。似乎输出文件的路径总是相对于 .Rmd 文件。我怎样才能做到这一点?
htmlreport <- function(output_path = NULL){
f <- system.file("inst/rmd", "html_report.Rmd", package = "abc")
if (is.null(outputh_path)) {
output_path <- ?? "Choose output folder" ....??
}
rmarkdown::render(f, output_dir = output_path)
# and open the html report..?
}
解决方案
output_dir
可以是任何路径,不仅是相对于 rmd 文件。
要选择文件夹,您可以使用choose.dir()
基本 R 包中的utils
函数或函数selectDirectory()
中的函数rstudioapi
(这意味着它仅在函数从 启动时才有效rstudio
)
使用构造的 url显示browseURL
来自基本 R 包的 html 文件使用函数utils
paste0("file://",<full path of your file using / separator>)
推荐阅读
- json - 基于json数组从akka http响应中获取实体的序列
- javascript - 创建条件 if/else 语句以显示最终测验分数结果
- javascript - 填写完所有 Google 输入字段后提示“嗨”
- c# - 搜索功能未按预期工作
- python - IRC 消息随机不从机器人发送
- python - 如何比蛮力更好地从字典中构建 Plinko 单词板?
- button - 如何在带有图像的按钮中设置文本
- c - 为什么我的代码中的 if 语句不起作用?
- reactjs - 求Master-Detail Reactjs组件库
- php - 为什么在使用机器名运行脚本时无法在 php 中运行 exec?