我目前正在尝试用rmarkdown::render()
呈现我的report.Rmd
文档。但是,每当我运行它时,我都会得到这样的错误:
> rmarkdown::render("report.Rmd")
processing file: report.Rmd
|.... | 6%
ordinary text without R code
|......... | 12%
label: setup (with options)
List of 1
$ include: logi FALSE
Quitting from lines 9-46 (report.Rmd)
Error in open.connection(con, "rb") : cannot open the connection
第9-46行中的块大约包含以下内容:
{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(jsonlite)
here::i_am("README.md")
# Set paths up
config <- read_json("config.json")
output_dir <- config$data_output
base::load(file.path(output_dir, "file1.rda"))
base::load(file.path(output_dir, "file2.rda"))
[...]
我强烈怀疑这个问题与jsonlite::read_json()
是一致的,因为这是我通过注释掉其余部分(从底部开始)来发现问题的第一点。相同.json
文件中的相同路径在前面的分析步骤中有效,但我从一个项目子文件夹中运行该文件(因为我希望输出也保存在该子文件夹中)。
你能帮我想出一个解决方案吗?提前感谢您的帮助
发布于 2021-04-12 20:57:25
当路径中没有在参数中指定的确切文件时,将显示此错误。
命令here::i_am()
(和包here
一般)不会更改R正在使用的主路径(即在getwd()
中),它只是通过使用here("file")
而不是在参数中声明完整路径(例如"./path/to/file"
)来简化从主文件夹调用任何file
。
在这种情况下,正确的参数应该是read_json(here::here("config.json"))
https://stackoverflow.com/questions/67025260
复制相似问题