Error code when using read.csv

wafll

New Member
#1
Error code when using read.csv SOLVED

SOLVED
Hi

I am trying to load a csv file into R using the command

> Data<-read.csv("data.csv",header=T)

but I get the error code

Warning messages:
1: In if (!header) rlabp <- FALSE :
the condition has length > 1 and only the first element will be used
2: In if (header) { :
the condition has length > 1 and only the first element will be used

I've checked the directory is correct and I tried using the full file name F:\data.csv but that came up with the error code

Error in file(file, "rt") : cannot open the connection
In addition: Warning messages:
1: '\P' is an unrecognized escape in a character string
2: '\d' is an unrecognized escape in a character string
3: unrecognized escapes removed from "F:\data.csv"
4: In file(file, "rt") :
cannot open file 'F:data.csv': No such file or directory

What am I doing wrong because I have copied this from an old code and it worked then?
 
Last edited:

Link

Ninja say what!?!
#2
Using "Data<-read.csv("data.csv",header=T)" means that your csv file is in the same directory as your script file.

Using the full file name, you'll have to put in two slashes: "F:\\data.csv" so that R knows its a directory.

The first warning message is about the header. To be sure though, you should first fix your directory location. See if the second error still occurs.
 

wafll

New Member
#3
Thanks, I've sorted out the directory but its still coming up with the error

Warning messages:
1: In if (!header) rlabp <- FALSE :
the condition has length > 1 and only the first element will be used
2: In if (header) { :
the condition has length > 1 and only the first element will be used
 

Mike White

TS Contributor
#4
The warning message suggests that the length of the header parameter is greater than 1. Your code sets header=T and T is a shortcut for TRUE so the length should always be 1, however, if you have used T as an object earlier in the code this may be the cause of the problem as in the example below:
Code:
T<-c(1,2)
dat<-read.csv("data.csv",header=T)