Basic computer literacy
Learn about basic computer terminology
1 Some computer basics
In the tutorial last week you’ve been playing around with R, RStudio and R scripts.
But what if you want to import data in R?
Easy! You can use the read_*()
functions (*
is just a place holder for specific types of files to read, like read_csv()
or read_excel()
) to read your files into R. But before we dive in, let’s first talk about some computer basics. (You can skip this section if it’s too basic for you.)
1.1 Files, folder and file extensions
Files saved on your computer live in a specific place. For example, if you download a file from a browser (like Google Chrome, Safari or Firefox), the file is normally saved in the Download
folder.
But where does the Download
folder live? Usually, in your user folder! The user folder normally is the name of your account or a name you picked when you created your computer account. In my case, my user folder is simply called ste
.
So, let’s assume I download a file, let’s say big_data.csv
, in the Download
folder of my user folder.
Now we can represent the location of the big_data.csv
file like so:
ste/
└── Downloads/
└── big_data.csv
To mark that ste
and Downloads
are folders, we add a final forward slash /
. That simply means “hey! I am a folder!”. big_data.csv
is a file, so it doesn’t have a final /
.
Instead, the file name big_data.csv
has a file extension. The file extension is .csv
. A file extension marks the type of file: in this the big_data
file is a .csv
file, a comma separated value file (we will see an example of what that looks like later). The name of the file is of course up to the user, but if you change the file extension you might have trouble later reading the file, so don’t change the file extension part yourself!
Different file type have different file extensions:
- Excel files:
.xlsx
. - Plain text files:
.txt
. - Images:
.png
,.jpg
,.gif
. - Audio:
.mp3
,.wav
. - Video:
.mp4
,.mov
,.avi
. - Etc…
1.2 File paths
Now, we can use an alternative, more succinct way, to represent the location of the big_data.csv
:
ste/Downloads/big_data.csv
This is called a file path! It’s the path through folders that lead you to the file. Folders are separated by /
and the file is marked with the extension .csv
.
Now the million pound question: where does ste/
live on my computer???
User folders are located in different places depending on the operating system you are using:
On macOS: the user folder is in
/Users/
.- You will notice that there is a forward slash also before the name of the folder. That is because the
/Users/
folder is a top folder, i.e. there are no folders further up in the hierarchy of folders. - This means that the full path for the
big_data.csv
file on a computer running macOS would be:/Users/ste/Downloads/big_data.csv
.
- You will notice that there is a forward slash also before the name of the folder. That is because the
On Windows: the user folder is in usually
C:/Users/
, but the drive letter might not beC
. We will useC
for convenience here.- You will notice that
C
is followed by a colon:
. That is becauseC
is a drive, which contains files and folders.C:
is not contained by any other folder, i.e. there are no other folders aboveC:
in the hierarchy of folders. - This means that the full path for the
big_data.csv
file on a Windows computer would be:C:/Users/ste/Downloads/big_data.csv
.
- You will notice that
When a file path starts from a top-most folder, we call that path the absolute file path.
There is another type of file paths, called relative paths. A relative path is a partial file path, relative to a specific folder. You will learn how to use relative paths below, when we will go through importing files in R using R scripts below.
Importing files in R is very easy with the tidyverse packages. You just need to know the file type (very often the file extension helps) and the location of the file (i.e. the file path).
The next sections will teach you how to import data in R!