1 Getting Started
Objectives
- Understand the basics of how computers work
- Understand the file system mental model for computers
- Set up RStudio, R, Quarto, and python
- Be able to run demo code in R and python
1.1 Computer Basics
It is helpful when teaching a topic as technical as programming to ensure that everyone starts from the same basic foundational understanding and mental model of how things work. When teaching geology, for instance, the instructor should probably make sure that everyone understands that the earth is a round ball and not a flat plate – it will save everyone some time later.
We all use computers daily - we carry them around with us on our wrists, in our pockets, and in our backpacks. This is no guarantee, however, that we understand how they work or what makes them go.
1.1.1 Hardware
Here is a short 3-minute video on the basic hardware that makes up your computer. It is focused on desktops, but the same components (with the exception of the optical drive) are commonly found in cell phones, smart watches, and laptops.
When programming, it is usually helpful to understand the distinction between RAM and disk storage (hard drives). We also need to know at least a little bit about processors (so that we know when we’ve asked our processor to do too much). Most of the other details aren’t necessary (for now).
- Chapter 1 of Python for Everybody - Computer hardware architecture
1.1.2 Operating Systems
Operating systems, such as Windows, MacOS, or Linux, are a sophisticated program that allows CPUs to keep track of multiple programs and tasks and execute them at the same time.
1.1.3 File Systems
Evidently, there has been a bit of generational shift as computers have evolved: the “file system” metaphor itself is outdated because no one uses physical files anymore. This article is an interesting discussion of the problem: it makes the argument that with modern search capabilities, most people use their computers as a laundry hamper instead of as a nice, organized filing cabinet.
Regardless of how you tend to organize your personal files, it is probably helpful to understand the basics of what is meant by a computer file system – a way to organize data stored on a hard drive. Since data is always stored as 0’s and 1’s, it’s important to have some way to figure out what type of data is stored in a specific location, and how to interpret it.
That’s not enough, though - we also need to know how computers remember the location of what is stored where. Specifically, we need to understand file paths.
When you write a program, you may have to reference external files - data stored in a .csv file, for instance, or a picture. Best practice is to create a file structure that contains everything you need to run your entire project in a single file folder (you can, and sometimes should, have sub-folders).
For now, it is enough to know how to find files using file paths, and how to refer to a file using a relative file path from your base folder. In this situation, your “base folder” is known as your working directory - the place your program thinks of as home.
2 Setting up your computer
In this section, I will provide you with links to set up various programs on your own machine. If you have trouble with these instructions or encounter an error, post on the class message board or contact me for help.
Download and run the R installer for your operating system from CRAN:
- Windows: https://cran.rstudio.com/bin/windows/base/
- Mac: https://cran.rstudio.com/bin/macosx/
- Linux: https://cran.rstudio.com/bin/linux/ (pick your distribution)
If you are on Windows, you should also install the Rtools4 package; this will ensure you get fewer warnings later when installing packages.
More detailed instructions for Windows are available here
Download and install the latest version of python 3
- Then, install Jupyter using the instructions here
Download and install the latest version of RStudio for your operating system. RStudio is a integrated development environment (IDE) for R - it contains a set of tools designed to make writing R code easier.
Download and install the latest version of Quarto for your operating system. Quarto is a command-line tool released by RStudio that allows Rstudio to work with python and other R specific tools in a unified way.
In class activity
Open RStudio on your computer and explore a bit.
- Can you find the R console? Type in
2+2
to make sure the result is4
. - Run the following code in the R console:
install.packages(
c("tidyverse", "rmarkdown", "knitr", "quarto")
)
- Can you find the text editor?
- Create a new quarto document (File -> New File -> Quarto Document).
- Paste in the contents of this document.
- Compile the document and use the Viewer pane to see the result.
- If this all worked, you have RStudio, Quarto, R, and Python set up correctly on your machine.
- Additional instructions for installing Python 3 from Python for Everybody