R is an excellent, if occasionally frustrating, tool. I’m assuming if you are an R user reading this post, you’ve already started using RStudio to improve your user experience. If not, go get RStudio here— it color-codes your scripts, displays your objects and functions in the working environment, and has an integrated file browser. And it’s free!
Today I’m sharing an under utilized RStudio feature–Projects. Projects save me probably 20 min each work day while simultaneously improving my file management system and my ability to move between R and QGIS easily.
What is a Project? It’s basically a way to save what your RStudio environment looks like (including your data, open scripts, and working directory) and then switch to another saved environment for other stuff. I love that it makes switching between, say, classwork and research stuff, super easy.
To make a new project, you go to the little drop down menu in the upper right corner of you RStudio window:
Then when you click “New Project…” it will take you to another menu:
I always select “Existing Directory,” which takes you to a file browser and you can select an existing folder from there. I create a lot of my data files in QGIS, so it’s easiest for me to just create a Project in the same folder as the QGIS project I’m working on. If you want to learn more about the other options, check out the RStudio support page here.
When you make a project, it will automatically open. The working directory is set to the folder your project was made in. Then you can open whatever files you need and save things back to this folder easily. When you close the RStudio session, a pop up will invite you to save the current environment. To re-open the project, just use your file browser to navigate to the appropriate folder and double click on the RProject file. Super simple!
Other cool things: You can open multiple projects on the same computer! You can use the same variable names in both projects, and they won’t over-write each other. Since the project also saves your working environment, if you have a bunch of data saved in data frames and want to finish graphing it later, you won’t lose your place or have to rerun anything. If you need to open files that aren’t in the folder your project is in, you can still navigate to them using the usual file path functionality in R.
I can’t recommend projects highly enough. I hope they make your R experience a little more efficient and a little less frustrating!