错误“无法打开连接".在执行“编织HTML"时在RStudio中 [英] Error "cannot open the connection" in executing "knit HTML" in RStudio

查看:77
本文介绍了错误“无法打开连接".在执行“编织HTML"时在RStudio中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在RStudio中尝试编织HTML"时出现以下错误.

I am getting the below error when trying to "knit HTML" in RStudio.

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

I am using RStudio on a 64-bit win8 machine.

推荐答案

运行编织HTML"时,代码试图在.Rmd所在的同一目录中查找您正在读取的文件,因为将工作目录设置为该路径.据我所知,您有两种选择.

When you run "Knit HTML", the code is trying to find the file you're reading in the same directory where .Rmd is located because knitr sets the working directory to that path. As far as I see you have two options.

  • 尝试指定文件的绝对路径(不是很可靠,但在某些情况下很方便).
  • 找出文件的相对路径.如果您的.Rmd文件位于/中,数据位于/data中,则相对路径应为例如read.table("./data/myfile.csv"...). .表示这里"(getwd()所在的位置),两个点向上爬升目录结构,而指定目录则向下爬升结构.
  • Try specifying the absolute path to the file (not very robust, but handy in some cases).
  • Figure out the relative path to the file. If you have your .Rmd file in / and data in /data, relative path should be, e.g., read.table("./data/myfile.csv"...). . means "here" (wherever the getwd() is), two dots climb the directory structure up while specifying directories climbs the structure down.

这篇关于错误“无法打开连接".在执行“编织HTML"时在RStudio中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆