5 Loading and Saving Data
5.1 Loading Data
You first need to place your dataset into the RStudio environment to do your work. The datasets you will work with are in a native-R format, .RData
. To do this, you use the load()
command. Make sure to put quotation marks around the file name inside the parentheses. Here is an example.
load("smaller_anes_2020.RData")
5.2 Saving Data
You can reload your dataset every time you use it, but it is simpler to save the dataset and load that file. Use the save command. Make sure that you use the name that is in your work space in the save command and you should make sure that both names are the same. You can rename your working file if needed. I have changed the name and then saved the file below.
<- some_other_name
name_in_workspace save(name_in_workspace, file = "name_in_workspace.RData")
Using the Ethiopia survey in the World Values Survey dataset as an example your name could be:
save(ethiopia, file = "ethiopia.RData")
It is critical that you:
- put quotation marks (““) around the file name,
- and use
.RData
as a file extension.
5.2.1 A Note on Naming Datasets and Files
As you make changes in your dataset during the semester, you will want to save your updated file. Give each version a new name so that you can go back to your previous work. How to name your files? Here are a grew good practices.
- You cannot space in a file name.
- You cannot start a file name with a number.
- Make them easy to read. Use snake_case, underscores “_” between words.
- Make them easy to type, use all lower case.
- Don’t use words like “final”, rather number your files consistently.
So, if you are using the Ethiopia survey and make changes something like ethiopia_2.RData
works.