简体   繁体   中英

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

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

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 !

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM