# Saving the current R environment to a .RData file
save.image("my_environment.RData")
R projects
note you will not be expected to use R projects for MES 503. This introduction is for your own convenience and project management.
An R Project is a complete workspace. It allows you to manage multiple files, datasets, scripts, and other related assets, and provides an easy way to return to those projects at a later time.
How to create an R Project
Launch RStudio.
Navigate to
File -> New Project
.Specify the desired location for your project.
Choose the components to include, such as an existing directory or version control options.
To reopen a previously created R Project, you can use either of the “standard” methods:
double-click the associated
.Rproj
file in your file explorer.in RStudio,
File -> Open Project
.
Advantages for your Thesis Research (or other projcets)
Adaptive Working Directory: With R Projects, your designated working directory is always associated with your project. This facilitates a seamless transition between different computers or workstations or projects.
Comprehensive Workspace Saving: Beyond data, R Projects allow you to save scripts, visual plots, R markdown files, etc. Its a great way to organize and access your research by data project.
R Environments
An R environment is essentially a snapshot of your current R session. It encompasses various objects you’ve created, ranging from data frames, vectors, and matrices to custom functions and plots.
Saving Your Environment
To preserve your current R environment and safeguard your progress:
- Use the
save.image()
function.
Restoring a Saved Environment
To pick up where you left off:
- Use the
load()
function.
# Loading a saved R environment from a .RData file
load("my_environment.RData")
Advantages
Consistency: By restoring your environment, every object, and variable remains intact, minimizing room for discrepancies and errors.
Efficiency: No need to start from scratch ever. you can quickly pick back up where you left off in each data project, making the most of your valuable time. Note: this can work against you if you do not organize your scripts - remember, your script is your source of truth, not your R project. (this is why I chose to introduce R projects later than in previous semesters).