Reputation: 107
I'm new to R but am slowing getting the hang of the basics. However I'm struggling to save and then open my work. I am saving as an .RData file however the file appearis in Windows Explorer simple as a 'File'. When trying to load a workspace into R these files only show when I change 'Files of type' from '.RData' to 'All files' and it will refuse to open these files. What am I doing wrong?
Also - if this were to work correctly would this method be similar to opening up a saved Word document - in that everything is the same as it was when I saved it and I can just continue my work?
Many thanks
Upvotes: 3
Views: 11935
Reputation: 1351
I am writing a R code which uses for saving a workspace: suppose we have a object name x, we want to save it in D drive and I want to save it names as zian.
x<-c(1,2,3,4)
write.table(x,"D:\\zian.txt")
#here I saves a workspace as a txt file
write.csv(x,"D:\\zian.csv")
#here I save a workspace as a csv file
#or
save(object,filename="D:\\2nd")
#here you have a file in D drive name as 2nd and you want to save this object in this file.
Upvotes: 1
Reputation: 895
In R you can save two types of files, .RData which is called the workspace and contains all objects (data) you created in a session. You can check what is in the workspace by typing ls()
into the console. The other type is a .R file which is a simple script file and saves your code.
If you are working with the default R GUI, it helps to save an .RData file in your working directory, i.e. where your input data files are located, and load your R session from there by double clicking the .RData icon. Then open your script file (.R) from within the R GUI. Usually, I would not never save anything in my workspace, unless it is computationally intensive and takes minutes or longer to calculate by running the code in the script file.
Also make sure that when saving workspace files for the first time to keep the file ending (.RData) in the file name. It usually shows up highlighted in blue and once you type your file name its being deleted. Keeping it will identify the workspace file with an R icon. If you saved it without the .RData ending, you can also add it manually by clicking the saved workspace file and add .RData to the file name. When saving script files you actually have to add the ending yourself (.R).
So, the reason I am writing all this is because you said you clicked 'Open workspace', which doesn't exist to my knowledge. It's called 'Load workspace'. Did you perhaps try to open an .RData file by choosing 'Open script' instead?
I would have asked my last paragraph in the comment section but don't have enough reputation to comment. So let me know if this doesn't solve your problem and I will delete the answer.
Upvotes: 3