Skip to content

Commit

Permalink
update r install and other clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kriemo committed Nov 6, 2023
1 parent 0c420d1 commit fc7c9d8
Show file tree
Hide file tree
Showing 24 changed files with 198 additions and 129 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
*.gz
docs
.Rhistory
ex/problem-set-3/matrices_clustering_heatmaps_key.*
ex/problem-set-3/matrices_clustering_heatmaps_key.*
ps
Original file line number Diff line number Diff line change
Expand Up @@ -16,97 +16,120 @@ draft: false

This article will explain how to install R, Rstudio, and R packages.

**Please watch the video at the end of the article that gives an overview of using Rstudio and the Rmarkdown format.**
**Please [watch the video](#rmd_movie) that gives an overview of using Rstudio, installing packages, and the Rmarkdown format.**

## Download R
## Installing R

Download R from CRAN. Go to the CRAN homepage https://cran.r-project.org/. Select the link to download R for your operating system.

### MacOS
*If you already have R installed, we recommend upgrading to the latest version of R by following the directions below*

Install the newest R version (`4.2.1`). We recommend installing the version for Intel Macs. If you have a Mac with an M1 processor (click the Apple -> About this Mac, see information under `chip`), we still recommend using the Intel version of R as it is much easier to install packages built for the intel version at this time. Download the `.pkg` file, open and follow the prompts to install.
### Windows

Go to [CRAN](https://cran.r-project.org/), and click `Download R for Windows`. Next click the `base` link and select `Download R-4.3.2 for Windows` to download the `.exe` file. Open this file to install R.

### Windows
### MacOS

Go to [CRAN](https://cran.r-project.org/), and click `Download R for macOS`. Under `Latest Release` there are two options available depending on which CPU is used in your laptop. Mac uses either Intel (x86) or arm64 (i.e. M1 or M2) processors. You can determine which type you have by clicking on the Apple menu and selecting "About this Mac". Next to `Chip` or `Processor`, it will say either M1 or M2, if you have an arm64 CPU, or it will say Intel Core or similar, indicating you have an Intel x86 CPU.

Download the `R-4.3.2-arm64.pkg` for arm64 or `R-4.3.2-x86_64.pkg` for Intel x86. Open and follow the prompts to install.

Select the `base` link, then click `Download R-4.2.1 for Windows` to download the `.exe` file. Open this file to install R.

### Linux

If you are on linux, then follow the documentation for your linux OS.

## Download Rstudio
## Install Rstudio

Go to the [Rstudio website](https://rstudio.com/products/rstudio/download/#download) and download Rstudio Desktop for your OS.
Go to the [Rstudio website](https://posit.co/download/rstudio-desktop/#download) and download Rstudio Desktop for your operating system

Once downloaded and installed, open up `Rstudio` to complete the rest of the tutorial.


## Download compiler tools
## Install compiler tools

Some R package installations may require a compiler, which is usually not available by default on Windows or macOS.

### Windows

You need to install `Rtools` from CRAN. Follow this link to download RTools 4.3 using the `Rtools43 installer` https://cran.r-project.org/bin/windows/Rtools/ .

### MacOS

To install the necessary compilers, we will follow the recommend steps outlined by CRAN: https://mac.r-project.org/tools/

You will need to install the xcode command line tools if a package requires compilation. Open Rstudio and click on the "Terminal" pane. Alternatively you can open the Terminal app from `/Applications/Utilities/` (or use the search tool to search for terminal)
#### Xcode
First you will need to install the `Xcode` command line tools. To do so open Rstudio and click on the "Terminal" tab, which is to the right of the "Console" Tab. Alternatively you can open the Terminal app directly from `/Applications/Utilities/` or use the spotlight search tool, search for "terminal", and open the Terminal App.

Type the following into terminal:
Type the following into the terminal and hit `Enter`:

```bash
sudo xcode-select --install
```

Type in your macOS password, press enter and then click “Install”. This download will require ~9Gb. Verify the installation by typing into terminal:
When prompted for `Password:`, type in your macOS user password (you wont see any characters printed as you type), and press enter. Click “Install” in the pop up and agree to the license agreement (if you agree of course). This download will require ~9Gb of space so it will take some time to download and install. Verify the installation by typing into terminal:

```bash
gcc --version
```

Which should print something similar to this:
Which should print something similar to either this:

```bash
#' gcc (GCC) 4.8.5
#' Copyright (C) 2015 Free Software Foundation, Inc.
#' This is free software; see the source for copying conditions. There is NO
#' warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

```

Here's a [youtube video explainer](https://www.youtube.com/watch?v=Z01lzHNrSdU&feature=emb_title)

Next you need to install `gfortran`, which can be obtained from the CRAN instruction site above. We recommend using the intel version of R, so please follow the instructions for Intel Macs and install gfortran using the `gfortran-8.2-Mojave.dmg` installer.
or this:

```bash
#' Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
#' Apple clang version 13.0.0 (clang-1300.0.29.30)
#' Target: arm64-apple-darwin21.3.0
#' Thread model: posix
#' InstalledDir: /Library/Developer/CommandLineTools/usr/bin
```

Here's a [youtube video explainer](https://www.youtube.com/watch?v=Z01lzHNrSdU&feature=emb_title) that also shows the process.

#### gfortran

Next you need to install `gfortran`. If you've installed the most recent version of R (or at least 4.3.0), then you can install using the [gfortran-12.2-universal.pkg](https://mac.r-project.org/tools/gfortran-12.2-universal.pkg).

Once you've run the `gfortran` installer the last step is to make sure that this program is in your [`PATH`](https://en.wikipedia.org/wiki/PATH_(variable)). This step will make the gfortran program visible to R, and other programs.
Once you've run the `gfortran` installer the last step is to make sure that this program is in your [`PATH`](https://en.wikipedia.org/wiki/PATH_(variable)). This step will make the `gfortran` program visible to R, and other programs.

First determine which type of shell you have (typically bash or zsh). Execute the following in a terminal (click either on the terminal pane in Rstudio, or open the terminal app in macOS).

```bash
echo $SHELL
```

If you see `/bin/zsh` then make a plain text file called `.zshrc` in your home directory (e.g. `/Users/Your-macOS-username/`), if it doesn't already exist. If instead you see `/bin/bash` then make a file called `.bashrc` in your home directory, if it doesn't already exist. You can use Rstudio to make a new plain-text file (File->New file->Text) or by opening up the Textedit app, then click Format->Make Plain Text.
If you see `/bin/zsh` then make a plain text file called `.zshrc` in your home directory (e.g. `/Users/Your-macOS-username/.zshrc`), if it doesn't already exist. If instead you see `/bin/bash` then make a file called `.bashrc` in your home directory, if it doesn't already exist. You can use Rstudio to make a new plain-text file (File->New file->Text) or by opening up the Textedit app, then click Format->Make Plain Text.

Add the following line of text to the file (and keep any other text if already present).

```bash
export PATH=$PATH:/usr/local/gfortran/bin
export PATH=$PATH:/opt/gfortran/bin
```

Save the text file to your home directory. You may need to rename the file after saving to ensure that it doesn't end with `.txt.` (e.g. rename `.zshrc.txt` -> `.zshrc`). This file will be a hidden file. Hidden files can be seen in the Finder app by pressing `Command` + `Shift` + `.` (period) to toggle on/off visulizaing hidden files.
Save the text file to your home directory. You may need to rename the file after saving to ensure that it doesn't end with `.txt.` (e.g. rename `.zshrc.txt` -> `.zshrc`). This file will be a hidden file. Hidden files can be seen in the Finder app by pressing `Command` + `Shift` + `.` (period) to toggle on/off visualizing hidden files.

Close and reopen Rstudio.

### Windows

You need to install `Rtools` from CRAN. Go to this link and download the exe installer for your OS: https://cran.r-project.org/bin/windows/Rtools/
### Linux
You should have a compiler available already.

## Installing the tidyverse and Rmarkdown packages

Once you have R and Rstudio set up, open up Rstudio, then we will install packages. Packages are extensions to the base R installation that provide additionally functionality to the language. In this course we will use packages from the [tidyverse](https://www.tidyverse.org/), which is a collection of packages commonly used for data science and interactive data analysis. Installing the `tidyverse` package will install the [entire collection](https://www.tidyverse.org/packages/) of tidyverse packages.
Now that you have R and Rstudio set up we will install packages.

[CRAN](https://cran.r-project.org/) is the official R package repository. CRAN has 18,000+ packages, including the tidyverse packages. Packages from CRAN are installed using the `install.packages()` function. A successful install will only need to be done once for the course.
Packages are extensions to the base R installation that provide additionally functionality to the language. In this course we will use packages from the [tidyverse](https://www.tidyverse.org/), which is a collection of packages commonly used for data science and interactive data analysis. Installing the `tidyverse` package will install an [entire collection](https://www.tidyverse.org/packages/) of tidyverse packages.

[CRAN](https://cran.r-project.org/) is the official R package repository. CRAN has 18,000+ packages, including the tidyverse packages. Packages from CRAN are installed using the `install.packages()` R function. A successful install of a package will only need to be done once, until you update R to a new version.

Open Rstudio to launch R. Then in the console pane, execute the following command to install the [tidyverse](https://www.tidyverse.org/):

Expand Down Expand Up @@ -155,7 +178,7 @@ install.packages("rmarkdown")

and verify installation by running `library(rmarkdown)`

## Introduction to using Rstudio and Rmarkdown
## Introduction to using Rstudio and Rmarkdown {#rmd_movie}

Now that you have installed R and Rstudio, please watch this video (~20 minutes) that provides an overview of how to use Rstudio [IDE](https://en.wikipedia.org/wiki/Integrated_development_environment) and an introduction to the [Rmarkdown format](https://rmarkdown.rstudio.com/lesson-1.html).

Expand All @@ -166,9 +189,8 @@ Now that you have installed R and Rstudio, please watch this video (~20 minutes)

## (Appendix) Installing packages from other sources

**At this point you will only need to install the tidyverse and rmarkdown packages **

There are 2 additional commonly used repositories for R packages that you should know about:
There are 2 additional commonly used repositories for R packages. These are not needed to complete the prerequisite but are useful resources that you will use as you perform more coding in R.

1) [Bioconductor](https://bioconductor.org/) is a repository that hosts 2,000+ bioinformatics related packages.

Expand All @@ -191,5 +213,8 @@ For example to install the [LaCroixColorR package](https://github.com/johannesbj
```r
install.packages("remotes")
remotes::install_github('johannesbjork/LaCroixColoR')

# or equivalently you could use BiocManager, which uses remotes internally
BiocManager::install(`johannesbjork/LaCroixColoR`)
```

Loading

0 comments on commit fc7c9d8

Please sign in to comment.