Hello!
A couple of days ago, my partner showed me a website where you can check whether you perceive turquoise as a hue of green 🟢 or blue 🔵.
The funny thing is, depending on the day (and the angle at which I look at my screen), turquoise seems to be either very green or very blue hue to me. What's the moral of the story? Everything is relative and that's why today we will talk about relative pathways and organising your coding workspace.
Last week, we loaded the data using the absolute pathway (check it out here). This means we've given the computer the full address of the location where it can find the file we're interested in. However, that is not always the ideal way of loading a file.
Firstly, you have to copy the entire pathway, which is usually quite lengthy and we don’t like lengthy stuff.
Secondly, though it's maybe not the most obvious reason and I will not cover it here in detail, that creates some issues when sharing our workflow with collaborators. Since the pathway gives the instructions that are specific to your and only your computer, other users will have to alter such a pathway to be able to load the file properly.
Okay, I have to confess something. I’ve always had way too many folders (and yeah, I still do) filled with files that have the most random, vague names.
In my defence, I think we all like to live on the edge sometimes.
But when conducting data analysis for my master’s thesis, I really needed to change that. I couldn’t stand the adrenaline rush that came with me trying to figure out whether one of my data files was lost forever or just sitting in one of the dark corners of my laptop 😬.
To prevent heart attacks, it’s useful to create a folder with a project name 📁, e.g. “Blue Tits Tutorials”, and then create three subfolders in it: data, code and results🗂️. You can do it in your Documents folder or wherever it makes sense for you.
Once created, we should set up a current working directory, which is basically a space we are working in — we will load data into this space and export results or anything worth saving from this space. You can treat it as a way of telling the computer which folder you will use to write your R scripts in.
To do that, we can open RStudio, go to Session → Set Working Directory → Choose Directory and choose our code folder (since that's the folder you will be coding in).
If you are curious, you can also check how to set up a working directory using the setwd() command (short for “set working directory”).
If, at any point, you want to double-check in which directory you are currently, type in the console:
getwd()
Now, let’s download the blue tits data and save it into the data subfolder on your computer.
Load the data in RStudio by typing:
library(readr) # if you have this package already installed
bt_data <- read_csv("../data/blue_tits.csv")
Here, the two dots tell the computer to take a step out of the current working directory (i.e. code folder). Now we stand in the big mother folder (”Blue Tits Tutorials” if you stuck to that name), in which we can “see” the code, data and results subfolders. The “data” part in the pathway tells the computer to take us to the data subfolder, grab the blue_tits.csv file and bring it to us under the name bt_data. We give the instructions with respect to the directory we are working in, hence we use a relative pathway😊.
Just remember about the quotation marks, forward slashes and the correct file extension!
Now, to display the data, type:
view(bt_data)
Can you see it? Awesome!
You deserve a zoological tidbit as a reward.
Recently, one of the UK wildlife centres welcomed a southern cassowary chick. In case you didn’t know, cassowaries look like this (note this beautiful turquoise head!):
The media really enjoyed describing the chick as belonging to the “most dangerous” bird species, emphasizing its connection to dinosaurs. I find it somehow ironic because, although cassowaries do have strong beaks and very long claws, they are frugivores (which means that they eat more than five portions of fruits per day) and technically speaking, all birds are dinosaurs, be it a cassowary or a blue tit 🪺!
That’s all for today, see you next Wednesday!
Aga
PS: Here is the survey in which you can tell me what R topic you find particularly confusing and why you want to learn it so that we can shape this space together!
But the cassowaries on the picture are blue!