Reputation: 1771
I have the following code:
```{r}
library(sqldf)
library(caret)
library(ROCR)
turnover = read.csv("active_20120630.csv")
```
When I run the code in R Studio, everything is fine. But when I clicked Knit HTML
, I got the following errors after the last line turnover = read.csv("active_20120630")
:
## Warning: cannot open file 'active_20120630.csv': No such file or directory
## Error: cannot open the connection
Why I can run them in the console but not in the HTML output?
Thanks
Upvotes: 4
Views: 9021
Reputation: 59300
The error No such file or directory
means it cannot find the file. Given that the filename is relative to the current directory, you most probably are in one directory when you try it with R Studio and in another when you try it with knit.
Try using an absolute path for the file such as (Linux):
turnover = read.csv("/home/user/active_20120630.csv")
or (Windows)
turnover = read.csv("C:/My Project/active_20120630.csv")
Make sure to replace the path in the example above with the actual one.
Alternatively, you can modify your global settings in knit as @Mike.Gahan suggests.
Upvotes: 3
Reputation: 4615
You might want to add some stuff to your global settings.:
```{r global options, include=FALSE}
#set root directory
opts_knit$set(root.dir="~/your/working/directory")
```
Upvotes: 1