Here we discuss how to save, load, and quit R environments; see list and structure of objects, and remove objects; save, load, display, and clear commands list.
After installing R, it is important to learn the concepts on this page and also see the page on the working directory.
Function | Usage |
save.image() |
Save all the objects in your workspace |
save() |
Save certain objects in your workspace |
load() |
Load objects saved from an earlier session |
q() |
Quit session |
quit() |
Quit session |
ls() |
List all objects in a session |
str() |
See the structure of an object |
ls.str() |
See the structure of all the objects |
rm() |
Remove an object |
rm(list = ls()) |
Remove all the objects in a session |
savehistory() |
Save all the commands in a session |
loadhistory() |
Load the commands from an earlier session |
history() |
Display all the commands in a session |
CTRL + L | Clear all the commands in a session |
To save all objects in your workspace for the current session to the working directory, use:
For example:
Or save to a specific location:
# Windows
save.image("C:/Users/Public/Statscodes/Rdata/files/filename.RData")
# macOS
save.image("/Users/Public/Statscodes/Rdata/files/filename.RData")
Alternatively, to save only certain objects, use:
To load the objects saved from a workspace in an earlier session from the working directory, use:
Or from a specific location:
# Windows
load("C:/Users/Public/Statscodes/Rdata/files/filename.RData")
# macOS
load("/Users/Public/Statscodes/Rdata/files/filename.RData")
To quit your R session, use:
Or:
To see list of objects in your environment, use:
To see the structure of a specific object, use:
For example:
'data.frame': 6 obs. of 2 variables:
$ Time : num 1 2 3 4 5 7
$ demand: num 8.3 10.3 19 16 15.6 19.8
- attr(*, "reference")= chr "A1.4, p. 270"
To see the structure of all objects in your environment, use:
To remove specific objects, use:
To remove all objects in your environment, use:
To save all commands in your session, use:
If saved as above with no filename and to the default working directory, your commands list will be automatically loaded each time you launch R.
Or specify a filename, which will not be automatically loaded:
savehistory("filename.Rhistory")
# Or to specific locations
# Windows
savehistory("C:/Users/Public/Statscodes/Rdata/files/homework.Rhistory")
# macOS
savehistory("/Users/Public/Statscodes/Rdata/files/homework.Rhistory")
To load commands list from an earlier session, use:
loadhistory("filename.Rhistory")
# Or from specific locations
# Windows
loadhistory("C:/Users/Public/Statscodes/Rdata/files/homework.Rhistory")
# macOS
loadhistory("/Users/Public/Statscodes/Rdata/files/homework.Rhistory")
To display all commands in your session, use:
Or for limited number of commands, for example, the 10 most recent (default = 25), use:
Or for the default size, which is the 25 most recent, use:
To clear commands and results from your console, use:
CTRL + L. Note that you can still access the commands with the "up arrow" (\(\uparrow\)) on your keyboard and objects are still available.
The feedback form is a Google form but it does not collect any personal information.
Please click on the link below to go to the Google form.
Thank You!
Go to Feedback Form
Copyright © 2020 - 2024. All Rights Reserved by Stats Codes