# Error code when using read.csv

#### wafll

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

SOLVED
Hi

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

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
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:

##### Ninja say what!?!

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
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
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)

#### wafll

##### New Member
That was the first thing in the code, but I've sorted it now by putting TRUE instead of T. Thanks for the help.

#### amardan

##### New Member
Hi
It's very simple. Error is about T.
change T to TRUE.