8.2 RStudio: Step-by-step guide

This step-by-step guide provides written instructions and screenshots for getting started with RStudio on AnVIL.

8.2.1 Launch RStudio Cloud Environment

AnVIL is very versatile and can scale up to use very powerful cloud computers. It’s very important that you select a cloud computing environment appropriate to your needs to avoid runaway costs. If you are uncertain, start with the default settings; it is fairly easy to increase your compute resources later, if needed, but harder to scale down.

Note that, in order to use RStudio, you must have access to a Terra Workspace with permission to compute (i.e. you must be a “Writer” or “Owner” of the Workspace).

  1. Open Terra - use a web browser to go to anvil.terra.bio

  2. In the drop-down menu on the left, navigate to “Workspaces”. Click the triple bar in the top left corner to access the menu. Click “Workspaces”.

    Screenshot of Terra drop-down menu.  The "hamburger" button to extend the drop-down menu is highlighted, and the menu item "Workspaces" is highlighted.

  3. Click on the name of your Workspace. You should be routed to a link that looks like: https://anvil.terra.bio/#workspaces/<billing-project>/<workspace-name>.

  4. Click on the cloud icon on the far right to access your Cloud Environment options.

    Screenshot of a Terra Workspace. The cloud icon to create a new cloud environment is highlighted.

  5. In the dialogue box, click the “Settings” button under RStudio

    Screenshot of the Cloud Environment Details dialogue box. The Settings button under RStudio is highlighted.

  6. You will see some details about the default RStudio cloud environment, and a list of costs because it costs a small amount of money to use cloud computing.

    Screenshot of the RStudio Cloud Environment dialogue box. The cost to run the environment is highlighted.

  7. If you are uncertain about what you need, the default configuration is a reasonable, cost-conservative choice. It is fairly easy to increase your compute resources later, if needed, but harder to scale down. Click the “Create” button.

    Screenshot of the RStudio Cloud Environment dialogue box. The "CREATE" button is highlighted.

  8. Otherwise, click “CUSTOMIZE” to modify the environment for your needs.

    Screenshot of the RStudio Cloud Environment dialogue box. The "CUSTOMIZE" button is highlighted.

  9. The dialogue box will close and you will be returned to your Workspace. You can see the status of your cloud environment by hovering over the RStudio logo. It will take a few minutes for Terra to request computers and install software.

    Screenshot of a Terra Workspace. The hovertext for the RStudio icon is highlighted, and indicates that the status of the environment is "Creating".

  10. When your environment is ready, its status will change to “Running”. Click on the RStudio logo to open a new dialogue box that will let you launch RStudio.

    Screenshot of a Terra Workspace. The hovertext for the RStudio icon is highlighted, and indicates that the status of the environment is "Running".

  11. Click the launch icon to open RStudio. This is also where you can pause, modify, or delete your environment when needed.

    Screenshot of the RStudio Environment Details dialogue box. The "Open" button is highlighted.

  12. You should now see the RStudio interface with information about the version printed to the console.

    Screenshot of the RStudio environment interface.

8.2.2 Tour RStudio

Next, we will be using RStudio and the package Glimma to create interactive plots. See this vignette for more information.

  1. The Bioconductor team has created a very useful package to programmatically interact with Terra and Google Cloud. Install the AnVIL package. It will make some steps easier as we go along.

    Screenshot of the RStudio environment interface. Code has been typed in the console and is highlighted.

  2. You can now quickly install precompiled binaries using the AnVIL package’s install() function. We will use it to install the Glimma package and the airway package. The airway package contains a SummarizedExperiment data class. This data describes an RNA-Seq experiment on four human airway smooth muscle cell lines treated with dexamethasone.

{Note: for some of the packages, you will have to install packaged from the CRAN repository, using the install.packages() function. The examples will show you which install method to use.}

<img src="06-tools-rstudio_files/figure-html//1BLTCaogA04bbeSD1tR1Wt-mVceQA6FHXa8FmFzIARrg_g11f12bc99af_0_56.png" title="Screenshot of the RStudio environment interface. Code has been typed in the console and is highlighted." alt="Screenshot of the RStudio environment interface. Code has been typed in the console and is highlighted." width="480" />
  1. Load the example data.

    Screenshot of the RStudio environment interface. Code has been typed in the console and is highlighted.

  2. The multidimensional scaling (MDS) plot is frequently used to explore differences in samples. When this data is MDS transformed, the first two dimensions explain the greatest variance between samples, and the amount of variance decreases monotonically with increasing dimension. The following code will launch a new window where you can interact with the MDS plot.

    Screenshot of the Glimma popout showing the data in an MDS plot. All data points are blue.

  3. Change the colour_by setting to “groups” so you can easily distinguish between groups. In this data, the “group” is the treatment.

    Screenshot of the Glimma popout showing the data in an MDS plot. Data points are colored blue and orange by group. The colour by dropdown menu on the interactive plot is hightlighted.

  4. You can download the interactive html file by clicking on “Save As”.

    Screenshot of the Glimma popout showing the data in an MDS plot. The Save As menu is highlighted.

  5. You can also download plots and other files created directly in RStudio. To download the following plot, click on “Export” and save in your preferred format to the default directory. This saves the file in your cloud environment.

    Screenshot of the RStudio interface. A plot has been created. The Export menu has been highlighted.

  6. You should see the plot in the “Files” pane.

    Screenshot of the RStudio interface. A plot has been created. The saved pdf file is now visible under the "Files" pane.

  7. Select this file and click “More” > “Export”

    Screenshot of the RStudio interface. A plot has been created. The saved pdf file is now visible under the "Files" pane. The "More" and "Export" menus have been highlighted.

  8. Select “Download” to save the file to your local machine.

    Screenshot of the RStudio interface. The popup to download the selected file has been highlighted,

8.2.3 Pause RStudio

  1. The upper right corner reminds you that you are accruing cloud computing costs.

    Screenshot of the RStudio interface. The icon on the top right showing that the cloud environment is running is highlighted.

  2. You should minimize charges when you are not performing an analysis. You can do this by clicking on “Stop cloud environment”. This will release the CPU and memory resources for other people to use. Note that your work will be saved in the environment and continue to accrue a very small cost. This work will be lost if the cloud environment gets deleted. If there is anything you would like to save permanently, it’s a good idea to copy it from your compute environment to another location, such as the Workspace bucket, GitHub, or your local machine, depending on your needs.

    Screenshot of the RStudio interface. The stop icon on the top right which stops the cloud environment is highlighted.

8.2.4 Delete RStudio Cloud Environment

  1. Stopping your cloud environment only pauses your work. When you are ready to delete the cloud environment, click on the gear icon in the upper right corner to “Update cloud environment”.

    Screenshot of the Workspace page. The gear icon on the top right that updates the cloud environment is highlighted.

  2. Click on “Delete Environment Options”.

    Screenshot of the cloud environment popout. "Delete environment options" is highlighted.

  3. If you are certain that you do not need the data and configuration on your disk, you should select “Delete everything, including persistent disk”. If there is anything you would like to save, open the compute environment and copy the file(s) from your compute environment to another location, such as the Workspace bucket, GitHub, or your local machine, depending on your needs.

    Screenshot of the cloud environment popout. "Delete everything, including persistent disk" is highlighted.

  4. Select “DELETE”.

    Screenshot of the cloud environment popout. "Delete" is highlighted.

sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.5 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.10       highr_0.8         bslib_0.4.2       compiler_4.0.2   
##  [5] pillar_1.9.0      jquerylib_0.1.4   tools_4.0.2       digest_0.6.25    
##  [9] lattice_0.20-41   jsonlite_1.7.1    udpipe_0.8.3      evaluate_0.20    
## [13] lifecycle_1.0.3   tibble_3.2.1      png_0.1-8         pkgconfig_2.0.3  
## [17] rlang_1.1.0       Matrix_1.2-18     igraph_1.2.6      cli_3.6.1        
## [21] curl_4.3          yaml_2.2.1        xfun_0.26         fastmap_1.1.1    
## [25] dplyr_1.0.2       stringr_1.4.0     httr_1.4.2        knitr_1.33       
## [29] hms_0.5.3         fs_1.5.0          generics_0.0.2    vctrs_0.6.1      
## [33] sass_0.4.5        gitcreds_0.1.1    grid_4.0.2        rprojroot_2.0.3  
## [37] tidyselect_1.1.0  glue_1.4.2        data.table_1.13.0 R6_2.4.1         
## [41] cow_0.0.0.9000    fansi_0.4.1       textrank_0.3.0    ottrpal_1.0.1    
## [45] rmarkdown_2.10    bookdown_0.24     readr_1.4.0       purrr_0.3.4      
## [49] magrittr_2.0.3    htmltools_0.5.5   utf8_1.1.4        stringi_1.5.3    
## [53] cachem_1.0.7