[R-SIG-Mac] I'm new to R in a Mac. How do I specify the path in read.table()?

707 views
Skip to first unread message

Parkhurst, David F.

unread,
Feb 15, 2021, 8:15:03 AM2/15/21
to r-si...@r-project.org
I’ve tried for over an hour to figure this out with no luck. I’ve moved the text file (created from excel) to the desktop to simplify the path. If I click on the file and ask Get Info, it lists “Where” as iCloud Drive > Desktop. If I copy that to the clipboard and paste that into a read.table command in the R interface, it comes up as /Users/DFP/Desktop. But if I try read.table("\\Users\\DFP\\Desktop\\Monroe319Ecoli.txt"), I get No such file or directory. How can I get that file into a data frame?

[[alternative HTML version deleted]]

Peter West

unread,
Feb 15, 2021, 8:54:39 AM2/15/21
to Parkhurst, David F., r-si...@r-project.org
David,

I thought I saw advice on this issue already that noted you could not use backslashes in file paths on a Mac. Have you tried with “/Users/DFP/Desktop/Monroe319Ecoli.txt”? Do you come from a Windows background?

Peter

p...@ehealth.id.au
“Why does this generation seek a sign? Truly, I say to you, no sign will be given to this generation.”

> On 30 Jan 2021, at 6:25 am, Parkhurst, David F. <park...@indiana.edu> wrote:
>
> I�ve tried for over an hour to figure this out with no luck. I�ve moved the text file (created from excel) to the desktop to simplify the path. If I click on the file and ask Get Info, it lists �Where� as iCloud Drive > Desktop. If I copy that to the clipboard and paste that into a read.table command in the R interface, it comes up as /Users/DFP/Desktop. But if I try read.table("\\Users\\DFP\\Desktop\\Monroe319Ecoli.txt"), I get No such file or directory. How can I get that file into a data frame?


[[alternative HTML version deleted]]

_______________________________________________
R-SIG-Mac mailing list
R-SI...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Peter Dalgaard

unread,
Feb 15, 2021, 8:54:44 AM2/15/21
to Parkhurst, David F., r-si...@r-project.org
Just use forward slashes, backslashes is a Windows thing. I.e.

read.table("/Users/DFP/Desktop/Monroe319Ecoli.txt")

should do it. A generic trick is

x <- file.choose()
dd <- read.table(x)

(and then possible have a look at x)

-pd

> On 29 Jan 2021, at 21:25 , Parkhurst, David F. <park...@indiana.edu> wrote:
>
> I�ve tried for over an hour to figure this out with no luck. I�ve moved the text file (created from excel) to the desktop to simplify the path. If I click on the file and ask Get Info, it lists �Where� as iCloud Drive > Desktop. If I copy that to the clipboard and paste that into a read.table command in the R interface, it comes up as /Users/DFP/Desktop. But if I try read.table("\\Users\\DFP\\Desktop\\Monroe319Ecoli.txt"), I get No such file or directory. How can I get that file into a data frame?
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Mac mailing list
> R-SI...@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd....@cbs.dk Priv: PDa...@gmail.com

Ben Tupper

unread,
Feb 15, 2021, 8:54:48 AM2/15/21
to Parkhurst, David F., r-si...@r-project.org
Hi,

https://stat.ethz.ch/R-manual/R-devel/library/base/html/file.path.html

See the note at the bottom. It's liberating in many ways that R handles
the underlying details for you - use the forward slash and you'll be good
to go without regard to the platform.

I think using file.path() is the best way to go. Just do something like the
following...

filename <- file.path("Users", "DFP", "Desktop", "Monroe319Ecoli.txt")
x <- read.table(filename)

Cheers,
Ben


On Mon, Feb 15, 2021 at 8:14 AM Parkhurst, David F. <park...@indiana.edu>
wrote:
> _______________________________________________
> R-SIG-Mac mailing list
> R-SI...@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>


--
Ben Tupper
Bigelow Laboratory for Ocean Science
East Boothbay, Maine
http://www.bigelow.org/
https://eco.bigelow.org

Parkhurst, David F.

unread,
Feb 15, 2021, 9:35:14 AM2/15/21
to Peter Dalgaard, r-si...@r-project.org
Thanks. As I’ve said elsewhere, I thought I had seen in something I read that those double backslashes were required in a Mac.

From: Peter Dalgaard <pda...@gmail.com>
Date: Monday, February 15, 2021 at 8:31 AM
To: Parkhurst, David F. <park...@indiana.edu>
Cc: r-si...@r-project.org <r-si...@r-project.org>
Subject: Re: [R-SIG-Mac] I'm new to R in a Mac. How do I specify the path in read.table()?
Just use forward slashes, backslashes is a Windows thing. I.e.

read.table("/Users/DFP/Desktop/Monroe319Ecoli.txt")

should do it. A generic trick is

x <- file.choose()
dd <- read.table(x)

(and then possible have a look at x)

-pd

> On 29 Jan 2021, at 21:25 , Parkhurst, David F. <park...@indiana.edu> wrote:
>
> I�ve tried for over an hour to figure this out with no luck.  I�ve moved the text file (created from excel) to the desktop to simplify the path.  If I click on the file and ask Get Info, it lists �Where� as  iCloud Drive > Desktop.  If I copy that to the clipboard and paste that into a read.table command in the R interface, it comes up as /Users/DFP/Desktop.  But if I try read.table("/Users\DFP\Desktop\Monroe319Ecoli.txt"), I get No such file or directory.  How can I get that file into a data frame?

Parkhurst, David F.

unread,
Feb 15, 2021, 9:46:00 AM2/15/21
to Ben Tupper, r-si...@r-project.org
Wow. That looks useful, especially when I don’t want to put the file to be read on the desktop. Thanks.

From: Ben Tupper <btu...@bigelow.org>
Date: Monday, February 15, 2021 at 8:52 AM
To: Parkhurst, David F. <park...@indiana.edu>
Cc: r-si...@r-project.org <r-si...@r-project.org>
Subject: Re: [R-SIG-Mac] I'm new to R in a Mac. How do I specify the path in read.table()?
Hi,

https://stat.ethz.ch/R-manual/R-devel/library/base/html/file.path.html

See the note at the bottom. It's liberating in many ways that R handles the underlying details for you - use the forward slash and you'll be good to go without regard to the platform.

I think using file.path() is the best way to go. Just do something like the following...

filename <- file.path("Users", "DFP", "Desktop", "Monroe319Ecoli.txt")
x <- read.table(filename)

Cheers,
Ben


On Mon, Feb 15, 2021 at 8:14 AM Parkhurst, David F. <park...@indiana.edu<mailto:park...@indiana.edu>> wrote:
I’ve tried for over an hour to figure this out with no luck. I’ve moved the text file (created from excel) to the desktop to simplify the path. If I click on the file and ask Get Info, it lists “Where” as iCloud Drive > Desktop. If I copy that to the clipboard and paste that into a read.table command in the R interface, it comes up as /Users/DFP/Desktop. But if I try read.table("\\Users\\DFP\\Desktop\\Monroe319Ecoli.txt"), I get No such file or directory. How can I get that file into a data frame?

[[alternative HTML version deleted]]

_______________________________________________
R-SIG-Mac mailing list
R-SI...@r-project.org<mailto:R-SI...@r-project.org>

Parkhurst, David F.

unread,
Feb 15, 2021, 9:46:09 AM2/15/21
to Peter West, r-si...@r-project.org
I’ve got it working now given help from several people. Yes, I’ve used windows since it first came out, and DOS before that. I switched to a Mac maybe 18 months ago when MS said they wouldn’t support windows 7 any more, and I didn’t like my wife’s windows 10. I’m still learning (and have just taken up R after not using it for years.). The Apple support people have taught me a lot!

From: Peter West <p...@pbw.id.au>
Date: Monday, February 15, 2021 at 8:30 AM
To: Parkhurst, David F. <park...@indiana.edu>
Cc: r-si...@r-project.org <r-si...@r-project.org>
Subject: Re: [R-SIG-Mac] I'm new to R in a Mac. How do I specify the path in read.table()?
David,

I thought I saw advice on this issue already that noted you could not use backslashes in file paths on a Mac. Have you tried with “/Users/DFP/Desktop/Monroe319Ecoli.txt”?  Do you come from a Windows background?

Peter

mailto:p...@ehealth.id.au
“Why does this generation seek a sign? Truly, I say to you, no sign will be given to this generation.”


On 30 Jan 2021, at 6:25 am, Parkhurst, David F. <mailto:park...@indiana.edu> wrote:

I�ve tried for over an hour to figure this out with no luck.  I�ve moved the text file (created from excel) to the desktop to simplify the path.  If I click on the file and ask Get Info, it lists �Where� as  iCloud Drive > Desktop.  If I copy that to the clipboard and paste that into a read.table command in the R interface, it comes up as /Users/DFP/Desktop.  But if I try read.table("\\Users\\DFP\\Desktop\\Monroe319Ecoli.txt"), I get No such file or directory.  How can I get that file into a data frame?

Reply all
Reply to author
Forward
0 new messages