Skip to content

Commit 87f699a

Browse files
author
Susan Vanderplas
committed
Python your turn, restructure R installation for different operating systems and a simpler appearance.
1 parent 4ce1824 commit 87f699a

File tree

1 file changed

+68
-13
lines changed

1 file changed

+68
-13
lines changed

part-tools/02-setting-up-computer.qmd

+68-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## What are you asking me to install?
99

10-
It's generally a good idea to be skeptical when someone is telling you to install things.
10+
It's a good idea to be skeptical when someone is telling you to install things.
1111
🤨 Here's a very broad overview of what each of these programs or services does and why I'm asking you to install or sign up for them.
1212

1313
| Program | Logo | Purpose |
@@ -29,23 +29,37 @@ While some parts of this book are fairly language-agnostic (R and python are bot
2929

3030
If you're just trying to learn R, perhaps you don't need to install python or quarto.
3131
If you're not working with other people, maybe you don't need to install `git`.
32-
You are welcome to make those executive decisions for yourself, but if you're not sure, you might just want to install the whole toolbox - you'll hopefully learn how to use all of the tools along the way, and it'll be less confusing later if you already have access to all of the tools and don't need to go back and get something else when you need it.
32+
You are welcome to make those decisions for yourself, but if you're not sure, you might just want to install the whole toolbox - you'll hopefully learn how to use all of the tools along the way, and it'll be less confusing later if you already have access to all of the tools and don't need to go back and get something else when you need it.
3333

3434
## Installation Process
3535

3636
In this section, I will provide you with links to set up various programs on your own machine.
3737
If you have trouble with these instructions or encounter an error, post on the class message board or contact me for help.
3838

39-
1. Download and run the R installer for your operating system from CRAN:
39+
1. Install R (and associated tools)
4040

41-
- {{< fa brands windows >}} Windows: <https://cran.rstudio.com/bin/windows/base/>
42-
- {{< fa brands apple >}} Mac: <https://cran.rstudio.com/bin/macosx/>
43-
- {{< fa brands linux >}} Linux: <https://cran.rstudio.com/bin/linux/> (pick your distribution)
41+
::: panel-tabset
4442

45-
If you are on {{< fa brands windows >}} Windows, you should also install the [Rtools4 package](https://cran.rstudio.com/bin/windows/Rtools/); this will ensure you get fewer warnings later when installing packages.
46-
47-
If you are on {{< fa brands apple >}} Mac, you should also install XCode, which is a set of developer tools. You can get it from the App store, but it's better to set yourself up with [Homebrew](https://brew.sh/) and then use homebrew to install XCode. If you prefer a different package manager, that's fine - Homebrew is widely used, but there are other options. Ultimately, you just need to have XCode so that you can compile R packages.
43+
### {{< fa brands windows >}} Windows
4844

45+
1. Get the R installer from CRAN: https://cran.rstudio.com/bin/windows/base/
46+
47+
2. Install the Rtools4 package that matches the R version you installed: https://cran.rstudio.com/bin/windows/Rtools/
48+
For example, if you installed R 4.4.3, you should download RTools 4.4. If you installed R 4.0.1, you should install RTools 4.0.
49+
50+
### {{< fa brands apple >}} Mac
51+
52+
1. Get the R installer from CRAN: https://cran.rstudio.com/bin/macosx/
53+
54+
2. Install XCode - a set of developer tools - so that you can install R packages more easily. There are two ways to do this:
55+
56+
a. Get XCode [from the App store directly](https://apps.apple.com/us/app/xcode/id497799835?mt=12) (simple, but you may have to do other things later)
57+
b. Install [Homebrew](https://brew.sh/) and then use homebrew to install XCode.^[If you prefer a different package manager, that's fine - Homebrew is widely used, but there are other options. Ultimately, you just need to have XCode so that you can compile R packages.]
58+
59+
I personally suggest option b, because Homebrew is used for a lot of different software-development related things, and having it will make life easier later.
60+
61+
::: {.callout-info collapse=true}
62+
#### Installing Homebrew + XCode
4963
```
5064
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
5165
```
@@ -55,6 +69,29 @@ brew install mas # Search the apple store
5569
mas search xcode # find xcode
5670
mas install 497799835 # install the program by ID
5771
```
72+
:::
73+
74+
75+
76+
### {{< fa brands linux >}} Linux
77+
78+
If you're using a distribution derived from Debian, Fedora, RedHat, Suse, or Ubuntu, follow the instructions below.
79+
80+
If you don't know your distribution (or if you're working on a derivative distribution, like Mint), you can figure out which set of instructions to follow by executing `lsb_release -a` in your system terminal.
81+
82+
If you're using Arch or another distribution that isn't derived from something listed above, google for instructions specific to your distribution - these instructions cover the most common, user-friendly distributions, but if you've chosen something more niche, it is assumed you can figure out how to install R. (If that isn't the case, leave a comment below with your distribution, so I know how best to update this book.)
83+
84+
---
85+
86+
#### Installation Instructions {-}
87+
88+
1. Get the R installer from CRAN: https://cran.rstudio.com/bin/linux/ - pick your distribution, and follow the distribution-specific instructions from there.
89+
90+
91+
You could install R using your package manager, but often this version is out of date. The instructions for each version will get you a more up-to-date version that will be easier to work with.
92+
93+
:::
94+
5895

5996
2. Download and install the latest version of [python 3](https://www.python.org/downloads/)
6097

@@ -96,14 +133,32 @@ If you want to be safe, go ahead and complete these steps as well.
96133
Open RStudio on your computer and explore a bit.
97134
98135
- Can you find the R console? Type in `2+2` to make sure the result is `4`.
99-
- Run the following code in the R console:
136+
- Run the following code in the R console to set up some basic packages:
137+
138+
``` r
139+
install.packages(c("tidyverse", "rmarkdown", "knitr", "quarto"))
140+
```
141+
142+
- Run the following code in the R console to set up Python:
100143

101144
``` r
102-
install.packages(
103-
c("tidyverse", "reticulate", "rmarkdown", "knitr", "quarto")
104-
)
145+
install.packages("reticulate")
146+
reticulate::virtualenv_create("stat-python") # Create a python environment
147+
reticulate::virtualenv_install("stat-python", c("numpy", "matplotlib", "pandas"))
105148
```
106149

150+
- Configure RStudio to use the python virtual environment you created:
151+
- Go to Tools -> Global Options -> Python
152+
- Click the Python interpreter Select button
153+
- Click Virtual Environments
154+
- Choose `stat-python` and hit "Select"
155+
- Restart RStudio when prompted to ensure the setting takes effect.
156+
157+
- Test out Python:
158+
- Go to the Console tab, and click on the R logo. A dropdown should be present with an option to select Python.
159+
- Wait for the Python prompt to appear (it will look like this: `>>>`)
160+
- Type `2 + 2`, hit enter, and make sure the result is `4`.
161+
107162
- Can you find the text editor?
108163
- Create a new quarto document (File -\> New File -\> Quarto Document).
109164
- Paste in the contents of [this document](../files/getting-started-r-python.qmd).

0 commit comments

Comments
 (0)