简体   繁体   中英

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

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). The code itself runs perfectly, but will not export through 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. More explicitly is that R is looking for the first file in this path:

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

change your wd to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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