2 Setup

2.1 R

Download and install the latest version of R.

2.2 RStudio

Download and install the latest version of RStudio.

There are a couple of useful settings to change in RStudio.

  • Tools / Global Options / Workspace: Restore .Rdata at startup = OFF
  • Tools / Global Options / Workspace: Save workspace to .Rdate on exit = Never

See Efficient R / Rstudio options for more information.

2.3 System dependencies

Windows users: install RTools.

Mac users: install Xcode and homebrew.

2.3.1 Spatial packages

To use spatial packages (eg.: sf), we need to install some system dependencies. The sf README has great instructions. Make sure to install these dependencies before trying to install spatial packages.

You may also find it easier to install using the R-universe version of packages, for example:

# Enable this universe
options(repos = c(
    rspatial = 'https://r-spatial.r-universe.dev',
    r_spatial = 'https://rspatial.r-universe.dev',
    CRAN = 'https://cloud.r-project.org'))

# Install sf and terra packages
install.packages(c('sf', 'terra'))

2.4 Literate programming

2.4.1 Quarto

A new literate programming tool from RStudio has been released for generating documents, websites, books, etc.

See the Get Started page for installation instructions.

After installing, check out the Hello, Quarto tutorial.

2.4.2 R Markdown

Install packages

install.packages(c('rmarkdown', 'bookdown', 'knitr'))

and tinytex helps us get TeX easily installed on your computer.

install.packages('tinytex')
tinytex::install_tinytex()

After installing tinytex, make sure to restart RStudio.

2.5 Git

Quick setup instructions here, but see the chapter on Git for more details.

2.5.1 Install git

Check out the great instructions in Happy Git With R. Be sure to check if git is installed first!

2.5.2 Hosting services

Historically, the lab primarily uses GitLab for private and group projects and GitHub for mirroring published projects or packages. This was largely dictated by GitHub’s lack of free, private repositories, and GitLab’s great continuous integration tools. Nowadays, the line is less clear - GitHub offers free private repositories and GitHub Actions. GitHub is more commonly used, especially in R package development. Take your pick or use both!

  1. Make an account on GitHub or GitLab (or both), and message Alec your usernames.
  2. Setup global git user name and email. See here.
  3. Setup a local folder on your computer to store all of your git repositories. I use a folder called ‘Local-git’ under Documents (/home/alecr/Documents/Local-git).

You can alternatively clone your repositories to different places on your hard drive, but I find it more straightforward to keep everything together.

2.5.3 Git clients

You may opt to use a git client to work with git on a regular basis. Again, see a great discussion in the Happy Git With R book here. We’ve tried using cross platform clients in the past to make it easy for folks to help each other. These days a solid recommendation is GitHub Desktop.