Hello, I have a problem when reading the data, for example, when I type "data(mv.csv)", there always returns a warning message: data set 'mv.csv' not found. Even when I add the document path "data('/Users/Documents/mv.csv'), the data are also not be able to find. Actually, this problem is not all about OpenMx, it relates to the whole R system. But I can only think of here to ask this question. Sorry, I forgot to say my computer system, it is MAC OS X 10.8.
Your help would be appreciated.
Ting
The data() function is only for loading datasets that are packaged with R or one of the packages you've installed.
If you're loading your own data from a comma separated values (csv) file, you probably want to use
read.csv()
. For other formats, check outread.table()
. The documentation for both is available by typing?read.table
at the R prompt, but the command line to read the file mv.csv will be some variant of
myData <- read.csv("mv.csv")
Hope that helps.
Thanks, that helps a lot. But when I use the command
read.csv('mv.csv'),
I get this:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file 'mv.csv': No such file or directory.
I am definitely positive that this dataset was stored in my Desktop. So, can you give me another clue?
Ting
What appears to be happening is that R (not OpenMx) does have the correct path to 'mv.csv'. I would go to the file on your desktop, right-click on it and bring up the properties window. There I would copy and paste the location of that file into your the parens in the read.csv() [Note: You may need to add an additional "\" after each directory in the path if you are working on a Windows].
If you are 100% sure that you have then correct path and R cannot find the file then it would seem that your version of R has become corrupted. In this case I would notify the R community and reinstall a new version R. FWIW, this possibility is extremely unlikely. The most probable case (if you can open the file with another program) is that folder or filename is not specified correctly.
Thanks a lot. After I inserted the slash,
myData <- read.csv('/Users/anna/Desktop/mv.csv'),
the warning message disappeared.
But I have set the working directory by setwd("/Users/anna/Desktop"), then why should I have to appoint the path of my dataset? I think it's troublesome.
When I was using windows system, not the MAC OS X right now, there was no need to indicate the path if there was a default folder.
Maybe I am wrong about this, can you tell me where my mistake is?
Thank you.
Ting
You should be able to run
setwd("/Users/anna/Desktop")
and then runread.csv("mv.csv")
and it should work as well as runningread.csv("/Users/anna/Desktop/mv.csv")
. If it doesn't, there's something wrong with the way R is working.But remember that R often doesn't keep track of your working directory between sessions; if you close R and open it again you will often have to run setwd again.
My guess is that your windows version had the default working directory set to be your Desktop, so that anything that was on the desktop was automatically available to R every time you opened it.
You can do that in the OS X R application by going to the R menu in the top left and selecting preferences, then picking startup and hitting the "Choose" button under "Initial Working Directory". Whatever directory you set there will be the one that R uses as its working directory whenever you open the R client. You might have to close R and reopen it for it to work.
You explained very clearly. That's very nice of you. I made it according your advice. Thank you again.