0

I have a strange problem. I want to read a CSV file, and I am perfectly able to do so in my console, but when I do the exact same line in my R markdown file, I get the error:

Error in file(file, "rt") : cannot open the connection

Why can I read the file in the console but not in the R Markdown file?

M--
  • 25,431
  • 8
  • 61
  • 93
madhatter5
  • 129
  • 2
  • 15

1 Answers1

2

Working directory of your Rmd differs from the ones of your R console. You should explicitly define the path to your file in the Rmd to avoid the error.

Another option would be moving your csv files to the folder that your markdown is existed.

In sum, You need to consider where the Rmd is, where the current directory of your console is and where your files are. If necessary move the files or change the directory or use explicit path.

Using getwd() you can get the current working directory for your markdown or your console.

M--
  • 25,431
  • 8
  • 61
  • 93