r - 在 RStudio 中执行 "cannot open the connection"时出现错误 "knit HTML"

标签 r rstudio r-markdown markdown knitr

尝试在 RStudio 中“编织 HTML”时出现以下错误。

  |................................                                 |  50%
  ordinary text without R code

  |.................................................................| 100%


processing file: Preview-b0c112a265.Rmd
label: unnamed-chunk-1

Quitting from lines 16-26 (Preview-b0c112a265.Rmd) 
Error in file(file, "rt") : cannot open the connection
Calls: <Anonymous> ... withVisible -> eval -> eval -> read.csv -> read.table -> file
Execution halted

我在 64 位 win8 机器上使用 RStudio。

最佳答案

当您运行“Knit HTML”时,代码会尝试在 .Rmd 所在的同一目录中查找您正在读取的文件,因为 knitr 设置了工作目录到该路径。据我所知,你有两个选择。

  • 尝试指定文件的绝对路径(不是很强大,但在某些情况下很方便)。
  • 找出文件的相对路径。如果您的 .Rmd 文件位于 / 中,数据位于 /data 中,则相对路径应为,例如 read.table( “./data/myfile.csv”...). 表示“此处”(无论 getwd() 所在的位置),两个点使目录结构向上爬,而指定目录则使结构向下爬。

关于r - 在 RStudio 中执行 "cannot open the connection"时出现错误 "knit HTML",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26994958/

相关文章:

r - 如何在 Shiny 中渲染循环内框的 html 内容?

r - 具有多个观察员的 Shiny 传单 map

r - 在 block 中产生与内联代码相同数量的数字

r - 在 Rprofile.site 中使用 .libPaths 更改 R 默认库路径失败

r - 将 R 文件转换为 R markdown 时出现问题

r-markdown - 如何在R Markdown Beamer中的目录幻灯片中添加标题

r - 对每一行的元素应用一个函数,然后总结

r - 错误 : Python module 'cleannlp' not found. 安装:pip install cleannlp in R

css - 将自定义 CSS 标签添加到 RMarkdown html 文档

r - 使用 lubridate 在一列中格式化多种日期格式