0

I am trying to knit a document but I am getting an error on the read.csv function which works fine if I run it from the RMarkdown or from the console.

I have searched but could only find solutions related to reading a csv from a URL. R read.csv from URL error in knitr

```{r}
# This analysis uses the National Names dataset
national_names_raw <- read.csv("NationalNames.csv")
```

This is the error I get...

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

Any help is appreciated.

Community
  • 1
  • 1
Kier
  • 21
  • 2
  • 2
    It looks like `read.csv()` can't find the file. Is the CSV file in the same directory as the .Rmd file you are knitting? You could also try using an absolute filepath instead of a relative one. – Keith Hughitt Aug 19 '16 at 17:25
  • To second the above comment, it is probable that `knitr` is running in a different directory than NationalNames.csv. Try adding the absolute path to check this. If this is the problem, then either keep the path, or figure out the directory in which `knitr` is running and set up a relative path from there. – lmo Aug 19 '16 at 17:26
  • You guys got it. I put in an absolute reference and it worked. Thanks – Kier Aug 20 '16 at 03:32

0 Answers0