Hopefully, you have already seen that utilizing R for engineering can unlock a host of powerful tools and techniques and give you the power of data visualization.
In using R, you will likely work with various objects (data files, scripts, analyses, reports etc.). As with other things, creating structure for how you accomplish things in R can be important for both effectiveness and efficiency.
RStudio has a very convenient feature called projects, which allows you to store everything related to a specific activity (say an engineering study or investigation) in a structured way. Take a look at this to see what projects are.
I’ve found that organizing everything in a project folder helps with a number of things; for one, everything is in one place so you don’t have to look for stuff. The other benefit is that once you crerate a project file and open that project in RStudio, the current working directory is set to the project directory, which is superuseful. I simply cannot emphasize enough how useful this is; if you have used RStudio, you know what I am talking about.
The create_project_folder() function
The create_project_folder() function of sherlock automates the task of creating a project file as well as an underlying subfolder structure (this is really the important part).
Let’s go through an example of what this looks like:
First, let’s say you decide to create a folder named Engineering_Projects to house your engineering projects – of course if you don’t already have one of those folders; maybe they are all over the place on your computer. Don’t worry, no judgement here, we’ve all been there!
# EDITION 010: CREATING A PROJECT SUBFOLDER STRUCTURE ----
# 0. LOAD PACKAGES ----
library(tidyverse)
library(sherlock)
# 1. CREATE A DIRECTORY NAMED ENGINEERING_PROJECTS ----
fs::dir_create(path = "Engineering_Projects")
You can either go about creating such a folder the good old-fashined way, that is manually in File Explorer (if you’re a Windows user), or you can do it programmatically using the dir_create() function from the fs package:
Awesomesauce. Now, this is where the create_project_folder() function comes into play. Let’s run the below code:
# 2. USE CREATE_PROJECT_FOLDER() ----
sherlock::create_project_folder(folder_name = "001_XYZ_Study", path = "Engineering_Projects/")
What we are saying here is that we want to create the folder named 001_XYZ_Study under the Engineering_Projects folder. There is, however, a lot more to what this function does. Not only does it create the folder itself for you…
…it also creates a project file (001_XYZ_Study.Rproj) as well as a complete subfolder structure.
This simple piece of functionality is a real time-saver; it keeps things in order and helps you stay organized, and we know that being organized means that you have more time to spend on stuff that matters.
I hope you enjoyed this week’s edition.
Resources for this week’s edition:
Resources for learning R:
- R for Data Science: a very thorough reference book by Hadley Wickham, the creator of the tidyverse. Absolutely free of charge and full of relevant examples and practice tests.
- ggplot2 reference book: a super detailed online book on the gpplot2 plotting package.
- My favorite R course, Business Science DS4B101-R: I learned R mainly throgh this course. Highly recommended if you want to get up to speed and beyond in a relatively short time. It has everything one will need from data cleaning to data visualization to modeling. This course is especially useful for engineers trying to learn or get good at R as it heavily focuses on the fundamentals but goes way beyond just that. Note: this is an affiliate link, meaning you get a hefty discount if you purchase a course, and I receive a small commission.
Leave a Reply