Using R and RStudio in Datahub/DSMLP


Using R and RStudio in Datahub/DSMLP


Getting Started

To begin using R and RStudio, navigate to datahub.ucsd.edu and log in using your AD account. Start the environment equipped with RStudio installed. It should look similar to this:

datahub for Rstudio description

Once the the home directory is loaded, click the New dropdown. Selecting the R option will create a new R notebook. Selecting the RStudio option will open an RStudio session in a new tab.

Select RStudio Option

Note: The first time you launch RStudio, you'll need to configure a personal package directory by running the following R commands in the RStudio Console tab:

dir.create("~/R")
dir.create("~/R/library")
.libPaths("~/R/library")

Getting Help In a R Notebook

If you know the name of the command you want to use but are unsure of how to use it, you can use ‘?command_name’ in a code cell and run it to bring up the documentation . (E.g. ?help)

Using R in Jupyter Notebook


What is R?

R is a programming language created specifically for statistics. R can be used interactively within a Jupyter notebook or be used to execute a list of commands stored in text file (called a script).

R Example Notebook

Here is an example R notebook that you can download and run on Datahub to get a basic understanding of how to use R in a Jupyter notebook.

Using RStudio


What is RStudio?

RStudio is an integrated development environment (IDE) for R. It includes a console for running commands, an editor that supports executing R code directly from the editor, a terminal, and several other features that helps manage multiple workflows while using R. For a more detailed list of RStudio feature, see the RStudio page.

Using RStudio

After selecting and launching RStudio, your window should look like the following:

Screenshot of RStudio

These are the tabs/windows that are most likely to be used:

Console

The Console tab is located in the bottom left corner of the RStudio environment. It displays a log of what a user does in the RStudio environment. The Console tab can also be used to execute commands and files by the user.

Terminal

The Terminal tab is located in the bottom left corner of the RStudio environment. It allows a user to interact with their files and folders using the command line.

Files

The Files tab is located in the bottom right corner of the RStudio environment. It displays all the files and folders associated with each user. It is similar to the `Files` tab in the home page of the Jupyter environment.

Packages

The Packages tab is located in the bottom right corner of the RStudio environment. It displays all the packages that are included with the RStudio environment. Packages can imported or detached by clicking on the box icon (this is similar to using the library and detach function).

File Window

This File Window is located in the top left corner of the RStudio environment. It will open up files that have been opened within tabs. This window has a heading with several options, including saving, searching, and running the file.

File window tab

If you still have questions or need additional assistance, please email datahub@ucsd.edu or visit support.ucsd.edu.