user2273555
user2273555

Reputation: 1

Cannot read file into R

I'n a new R user and I'm trying to read my file P506A-data-time-v3.csv into R, however it responds with:

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file '
P506A
-
data
-
time
.csv': Invalid argument

I changed the directory to the folder on my computer that the file was saved in.

So I looked up other similar questions and people said to use choose.file, however I think I entered it in correctly. The result R gave me was:

> file.choose
function (new = FALSE) 
.Internal(file.choose(new))
<bytecode: 0x07c80118>
<environment: namespace:base>
> P506A
Error: object 'P506A' not found
> -
+ data
Error in -data : invalid argument to unary operator
> -
+ timeP506A-data-time-v3<-read.table(file.choose(),header=T,sep="\t") 

Error in -timeP506A - data - time - v3 <- read.table(file.choose(), header = T,  :

  object 'timeP506A' not found

In addition: Warning message:

In read.table(file.choose(), header = T, sep = "\t") :`enter code here`

  incomplete final line found by readTableHeader on 'D:\Uni\114\Probelm Solving 

So it seems like a complicated problem too me, so any help with figuring out how to get R to read my file would be very much appreciated.

Thanks

Upvotes: 0

Views: 17633

Answers (4)

Irrfan23
Irrfan23

Reputation: 390

very late but correct answer I have also faced this issue, this is not a big issue. You must be giving wrong file name or not giving correct extension to the file.

Upvotes: 0

Michael Grossmann
Michael Grossmann

Reputation: 169

I had the same problem using R Studio (latest version) and with my workspace correctly set up. To be precise, I had:

file ‘FILENAME.csv’ has magic number 'YEAR,' Use of save versions prior to 2 is deprecated

So I changed the row 1 column 1 header 'YEAR' to something else, and the problem went away !

Upvotes: 1

mike_vyk
mike_vyk

Reputation: 1

I agree with other recommendations although here's something easier. First execute getwd(). Now is that the folder where your required file is in? Likely it is not. Hopefully you are using R Studio. If so, then manually go to the bottom right panel next to the console and click files, which is at the top left of that panel. Then click the the three dots "..." and go to your preferred working directory. Click Ok. Then click "More" which is next to a blue wheel and just to the left of the three dots. Then select "Set as Working Directory". That's it! :)

Upvotes: 0

Uselesssss
Uselesssss

Reputation: 2133

Try the following

File = read.csv("P506A-data-time-v3.csv", header = TRUE)

and you can also refer the following tutorial

http://www.cyclismo.org/tutorial/R/input.html#read

Upvotes: 4

Related Questions