Skip to contents

Introduction

In this guide, we will explore options for setting up an R environment. We will discuss local, remote, and virtual environments. Each have their own advantages and shortcomings. The best option for you will depend on your needs and preferences.

Environment setups

Local environments

Choosing to work with R locally means that you will install R and an IDE on your local computer. This approach offers the following advantages:

  • Fast and responsive performance
  • No reliance on internet connectivity
  • Flexibility to customize your environment

The main disadvantages of working locally are:

  • you will need to install R and an IDE on your local computer,
  • manage your own software environment, and
  • manage your own backups and version control for collaborative projects.

This can be a challenge for new users, but there are a number of resources available to help you get started and troubleshoot any issues you may encounter.

To get started, install R from CRAN. You can download the latest version of R for your operating system here. Once you have installed R, you will need to install an IDE. For complete beginners, I recommend RStudio, a free and open-source IDE for R. RStudio provides a number of features that make it easier to work with R. If you are new to R, but have experience with other programming languages, you may prefer to use a more general-purpose IDE such as VS Code.

Remote environments

You can also choose to work with R in the cloud, a remote environment. There are a number of cloud-based options for working with R, including Posit Cloud and Microsoft Azure. These options provide a pre-configured R environment that you can access from any computer with an internet connection.

Posit Cloud provides an environment where you can create, edit, and run R projects from anywhere with internet access. It offers several advantages:

  • No need to install R or RStudio locally
  • Access your projects from any device
  • Collaborate with others in real-time
  • Easily share your work

Some of the drawbacks of working in the cloud include:

  • Reliance on stable internet connection
  • Potential latency and performance issues
  • Limited customization options compared to a local setup

To get started with Posit Cloud, you will need to create an account. You can sign up for a free account here. Once you have created an account, you will see a list of spaces. By default you will have your personal workspace, but you can also join or be invited to other spaces.

Visit the Guide documentation to learn more about the features of Posit Cloud.

Virtual environments

If you are new to R, you may want to consider working in the cloud to get started. If you plan to continue to work with R in the future, you will most likely want to install R and an IDE on your local computer or explore using a virtual environment. Virtual environments, such as Docker, provide a way to use a pre-configured computing environment or create your own that you can share with others. Virtual environments are a good option if you want to ensure that everyone in your research group is working with the same computing environment. Pre-configured virtual environments exist for R through the Rocker project and can be used locally or in the cloud.

Using Docker with Rocker offers several benefits:

  • Reproducible environments
  • Simplified dependency management
  • Easy deployment and scaling

The drawbacks to using Docker with Rocker include:

  • Learning curve for setting up and managing Docker containers
  • Increased memory and resource requirements
  • Potential compatibility issues with certain packages or libraries

To start using Docker with Rocker, follow these steps:

  1. Install Docker on your local machine

  2. Pull the desired Rocker image from Docker Hub

    docker pull rocker/rstudio
  3. Run a container using the pulled image

    docker run -d -p 8787:8787 -e PASSWORD=your_password --name rstudio_container rocker/rstudio
  4. Access RStudio in your browser at http://localhost:8787 and log in with username rstudio and the password you set

Summary

In this guide, we have discussed strategies for working with R. All three options offer unique advantages. In Table 1, we summarize some of the characteristics, benefits, and drawbacks of each option.

Table 1: Comparison of different environments for working with R and RStudio
Environment Characteristics Benefits Drawbacks
Local (Computer) - R/RStudio installed locally
- Project files stored on local machine
- Accessible without internet connection
- Full control over software version and environment
- Fast and responsive performance
- No reliance on internet connectivity
- Ability to work offline
- Complete control over software version and environment
- Limited collaboration options
- Difficulty in sharing projects with others
- Potential compatibility issues with different operating systems
Remote (Cloud) - R/RStudio accessed via web browser
- Project files stored on cloud server
- Accessible from any device with internet connection
- Easy collaboration with others
- Automatic backups and version control
- No need for local installation or setup
- Easy access from anywhere
- Seamless collaboration with teammates
- Backup and version control provided by the cloud service
- Reliance on stable internet connection
- Potential latency and performance issues
- Limited customization options compared to a local setup
Virtual (Docker) - R/RStudio environment encapsulated in a Docker container
- Project files stored locally or on the cloud
- Consistent environment across different machines
- Reproducible and portable environment
- Easy setup and sharing of the container
- Flexibility to run on different operating systems
- Isolation from host system dependencies
- Learning curve for setting up and managing Docker containers
- Increased memory and resource requirements
- Potential compatibility issues with certain packages or libraries

Give them a try and see which one works best for your needs! Remember, you can always switch between different environments as your needs change.

References