directing lavaan to data on a mac

18 views
Skip to first unread message

Lois Shelton

unread,
Feb 20, 2019, 3:54:12 PM2/20/19
to lavaan

How can I tell lavaan where to find data in the Mac environment? My .txt data file is located on my Mac HD; the path for the file is: Macintosh HD Users gjh2293 Downloads Text-Files-for-R gss2014_names.txt. 
See syntax and error message below:

> library (lavaan)
This is lavaan 0.6-3
lavaan is BETA software! Please report any bugs.
> gssdata <- read.table("MacintoshHD/Users/gjh2293/Downloads/Text-Files-for-R/gss2014_names.txt", header=T)
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'MacintoshHD/Users/gjh2293/Downloads/Text-Files-for-R/gss2014_names.txt': No such file or directory

Many thanks in advance!

Mark Seeto

unread,
Feb 20, 2019, 4:05:20 PM2/20/19
to lavaan
Hi Lois, 

read.table() is an R function, not a lavaan function. Can you normally get read.table() to work?

You might have to try 

read.table("/MacintoshHD/Users/gjh2293/Downloads/Text-Files-for-R/gss2014_names.txt", header=T)

or

read.table("~/MacintoshHD/Users/gjh2293/Downloads/Text-Files-for-R/gss2014_names.txt", header=T)

or

read.table("~/Users/gjh2293/Downloads/Text-Files-for-R/gss2014_names.txt", header=T)

or something similar.

Mark

Edward Rigdon

unread,
Feb 20, 2019, 4:07:18 PM2/20/19
to lav...@googlegroups.com
May I suggest using the file.choose() function. To put the file path and name into an object called fname:

fname<-file.choose()

Executing this line will open a standard file navigation dialog. Navigate to your data file and select it, and that will put the file path and name into the fname object, which you can then use in your "read" statement.


--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

Christopher David Desjardins

unread,
Feb 20, 2019, 4:16:29 PM2/20/19
to lavaan
Just to add to Mark's comment.

What do you get from:

getwd()

Does it say "/Users/gjh2293"?  If so, then you should be able to do

read.table("Downloads/Text-Files-for-R/gss2014_names.txt", header=T)

You can also use:

read.table("~/Downloads/Text-Files-for-R/gss2014_names.txt", header=T)

which would be shorthand for

read.table("/Users/gjh2293/Downloads/Text-Files-for-R/gss2014_names.txt", header=T)

If it says "/Users/gjh2293" and those commands don't work, then your file isn't in that location.

This is more an R-help question.

Chris




--

Lois Shelton

unread,
Feb 20, 2019, 5:51:22 PM2/20/19
to lav...@googlegroups.com
Hello!

Mark, Edward and Chris - you are the best! I am a newbie at both R and lavaan, and so I appreciate you clarifying things for me.

The syntax statements that worked on my Mac laptop were:

gssdata <- read.table (“/Users/gjh2293/Downloads/Text-Files-for-R/gss2014_names.txt”, header=T)

gssdata <- read.table (“~/Downloads/Text-Files-for-R/gss2014_names.txt”, header=T)

getwd()

gave me the exact location plus I appreciated learning about 

file.choose ()

Yes, this is more of an R question, so I am all the more grateful to you for answering on the lavaan site.
Again, many thanks!

Lois



In file(file, "rt") :0

  cannot open file 'MacintoshHD/Users/gjh2293/Downloads/Text-Files-for-R/gss2014_names.txt': No such file or directory

Many thanks in advance!

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages