0

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
kslayerr
  • 819
  • 1
  • 11
  • 21
  • 2
    I wouldn't use setwd within a markdown document – Richard Telford Nov 21 '17 at 22:19
  • I would use compile the markdown once using `getwd()` to display the working directory, then use relative paths to read in your csv files, which should be nested within your package. – Jthorpe Nov 21 '17 at 22:21
  • I still don't really know what the error is, but I just pulled in one dataset at a time in different R markdown documents, and that seems to work. Pulling in 2 into the same Rmd yields the error above. – kslayerr Nov 22 '17 at 15:46

1 Answers1

1

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/")
Alejandro Andrade
  • 2,196
  • 21
  • 40