I have been trying to import a csv file to r. but I get the same message everytime. the message is Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'Users:/sezginozcan/Downloads/beer.data.csv': No such file or directory I use mac. I tried this command also a<-read.table("clipboard",sep=?\t?,row.names=1,header=T) Error: unexpected input in "a<-read.table("clipboard",sep=?" I will appreciate if you help me before I get crazy. thank you
There's not usually a colon in Mac file paths. I would have expected "/Users/sezginozcan/Downloads.beer.data.csv" instead. Did you check that? More generally, type dir(PATHWHEREYOUTHINKFILEIS) and see if it really is there. Michael On Thu, Feb 9, 2012 at 10:20 PM, sezgin ozcan <szgozcan at gmail.com> wrote:> I have been trying to import a csv file to r. but I get the same message everytime. the message is > > Error in file(file, "rt") : cannot open the connection > In addition: Warning message: > In file(file, "rt") : > ?cannot open file 'Users:/sezginozcan/Downloads/beer.data.csv': No such file or directory > > I use mac. > I tried this command also > a<-read.table("clipboard",sep=?\t?,row.names=1,header=T) > Error: unexpected input in "a<-read.table("clipboard",sep=?" > > I will appreciate if you help me before I get crazy. > thank you > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi Sezgin, An alternative option If you do not know the path to your file, is to use file.choose() within read.table() to locate it in your machine: a <- read.table(file.choose(), sep = "\t", rownames = 1, header = TRUE) # a window will pop up! head(a) However, in my experience, it is always better to know where the file is located. HTH, Jorge.- On Thu, Feb 9, 2012 at 10:20 PM, sezgin ozcan <> wrote:> I have been trying to import a csv file to r. but I get the same message > everytime. the message is > > Error in file(file, "rt") : cannot open the connection > In addition: Warning message: > In file(file, "rt") : > cannot open file 'Users:/sezginozcan/Downloads/beer.data.csv': No such > file or directory > > I use mac. > I tried this command also > a<-read.table("clipboard",sep=”\t”,row.names=1,header=T) > Error: unexpected input in "a<-read.table("clipboard",sep=‚" > > I will appreciate if you help me before I get crazy. > thank you > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
On Feb 10, 2012, at 04:20 , sezgin ozcan wrote:> I use mac. > I tried this command also > a<-read.table("clipboard",sep=?\t?,row.names=1,header=T)Something is wrong with those quotes around \t... Also, last I needed this, using file="clipboard" to read from the clipboard didn't work on Mac, but file=pipe("pbpaste") did. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
First, make sure the file name is correct. Second, try list.files("Users:/sezginozcan/Downloads/") to see if the file is listed and you are looking in the correct folder. Third, you may be able to locate and open the file using A <- read.table(file.choose(), sep="\t", row.names=1, header=T) I believe that "clipboard" works only on Windows computers. ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of sezgin ozcan Sent: Thursday, February 09, 2012 9:21 PM To: r-help at stat.math.ethz.ch Subject: [R] Importing a CSV file I have been trying to import a csv file to r. but I get the same message everytime. the message is Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'Users:/sezginozcan/Downloads/beer.data.csv': No such file or directory I use mac. I tried this command also a<-read.table("clipboard",sep="\t",row.names=1,header=T) Error: unexpected input in "a<-read.table("clipboard",sep=," I will appreciate if you help me before I get crazy. thank you ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
---------- Forwarded message ---------- From: Gyanendra Pokharel <gyanendra.pokharel@gmail.com> Date: Fri, Feb 10, 2012 at 11:13 AM Subject: Re: [R] Importing a CSV file To: sezgin ozcan <szgozcan@gmail.com> You save your file in your own folder either in desktop or in document where ever you want and serach the file using the command mydatafile <- read.csv(file.choose()) then open the file Cheers On Thu, Feb 9, 2012 at 10:20 PM, sezgin ozcan <szgozcan@gmail.com> wrote:> I have been trying to import a csv file to r. but I get the same message > everytime. the message is > > Error in file(file, "rt") : cannot open the connection > In addition: Warning message: > In file(file, "rt") : > cannot open file 'Users:/sezginozcan/Downloads/beer.data.csv': No such > file or directory > > I use mac. > I tried this command also > a<-read.table("clipboard",sep=”\t”,row.names=1,header=T) > Error: unexpected input in "a<-read.table("clipboard",sep=‚" > > I will appreciate if you help me before I get crazy. > thank you > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
I think you must have given the path to the file wrong. Assuming you are using R.app, try infile <- file.choose() And then give infile to the read.csv() function. Then print the value of infile to find out what the path really is. Probably, you wanted '/Users/sezginozcan/Downloads/beer.data.csv' -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 2/9/12 7:20 PM, "sezgin ozcan" <szgozcan at gmail.com> wrote:>I have been trying to import a csv file to r. but I get the same message >everytime. the message is > >Error in file(file, "rt") : cannot open the connection >In addition: Warning message: >In file(file, "rt") : > cannot open file 'Users:/sezginozcan/Downloads/beer.data.csv': No such >file or directory > >I use mac. >I tried this command also >a<-read.table("clipboard",sep=?\t?,row.names=1,header=T) >Error: unexpected input in "a<-read.table("clipboard",sep=?" > >I will appreciate if you help me before I get crazy. >thank you > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.