简体   繁体   English

无法将csv读取到R Markdown中:文件错误(文件,“ rt”)

[英]Cannot read csv into R Markdown: Error in file(file, “rt”)

I have been reading other questions on this topic (see read.table() and read.csv both Error in Rmd ), but I believe I have set my working directory fine and the answers are not adequately answering my question... 我一直在阅读有关此主题的其他问题(请参阅read.table()和read.csv均为Rmd中的Error ),但是我相信我已经将工作目录设置为正确,并且答案无法充分回答我的问题...

Here is my code: 这是我的代码:

---
title: "WQ"
author: "A"
date: "October 13, 2017"
output:
  html_document: 
    fig_height: 6
    fig_width: 12
classoption: landscape
---


```{r}
setwd("C:/Users/K/Box/Projects/DRIP/3. Data/working/R_markdown")
x <- read.csv("Nash_longform_subset.csv",as.is=T)
y <- read.csv("Nash_longform.csv", as.is=T)

```{r}

All files and the R markdown file are in the same folder (set above in the code). 所有文件和R markdown文件都在同一文件夹中 (在代码上方进行了设置)。 The code itself runs perfectly, but will not export through R Markdown... 代码本身运行完美,但不会通过R Markdown导出...

And I get the error: 我得到错误:

x Line 14 Error in file(file, "rt"): cannot open the connection calls: 
<Anonymous>... withVisible -> eval -> eval -> read.csv -> read.table -> file

The problem is that you are missing an slash in your wd so R doesn't find the document, that's what Error in file(file, “rt”) means. 问题是您在wd中缺少斜杠,因此R找不到文档,这就是file(file,“ rt”)中的Error的含义。 More explicitly is that R is looking for the first file in this path: 更明确的是R正在此路径中查找第一个文件:

"C:/Users/K/Box/Projects/DRIP/3. Data/working/R_markdownNash_longform_subset.csv"

change your wd to: 将您的wd更改为:

setwd("C:/Users/K/Box/Projects/DRIP/3. Data/working/R_markdown/")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM