Using and launching RStudio with .Rmd files

Allie Cliffe

You can keep your RStudio analysis by saving it as an R-Markdown file (.Rmd) in the Analyses tab of your workspace. Read on for the basics of launching RStudio from an .Rmd file and how to save, store, and delete it. 

Note: Terra only recognizes R-Markdown files with the extension  Rmd. The capital 'R' is required

Launching RStudio from an .Rmd file

All of your workspace's .Rmd files are listed under Your Analyses in the Analyses tab of your workspace. You can identify them by the "R" logo beside the filename. 
Screenshot of workspace Analyses tab with HelloWorld RMarkdown file in the Name column of the Your Analysis section and the R logo under the application column.

Follow the instructions below to launch an RStudio analysis from one of these files.

  • 1. Click on the .Rmd filename to open it.

    2. Click the Open button (with a rocket symbol) beside the Preview (Read only) tab. 

    3. In the RStudio Cloud Environment pane, click Create
    Screen capture of launching RStudio from an .Rmd file by clicking on the .Rmd file's name, clicking 'open,' then clicking 'create' to create an RStudio cloud environment. Once the cloud environment is ready, you will see a green dot under the R icon on the right-hand panel of your workspace's screen.

    4. Once your RStudio Cloud Environment is running, click the Open RStudio button.
    Screenshot of the Analyses tab with the Your cloud environment is ready popup and blue open RStudio button circled. A preview version of the file is visible in the main screen section

    5. This will open RStudio, and you can continue your analysis. 
    Screenshot of RStudio session in Terra with example standard output code in the entrypoint.out section at left, an empty environment section at the top right, and teh environment.out under files in the bottom right.

  • 1. Click on the .Rmd filename to open it.

    2. Click the R logo in the sidebar to resume the RStudio Cloud Environment.  

    3. Click Resume Environment (play icon). 
    Screen capture of starting an RStudio instance by resuming a paused Cloud Environemnt following the instructions above.
    The RStudio Cloud Environment will take a minute or two to resume.

    4. Once the environment is running (green dot in the sidebar), close the RStudio Cloud Environment pane ("x" at the top right) and click the Open RStudio button.
    Screenshot of the Analyses tab with the Your cloud environment is ready popup and blue open RStudio button circled. A preview version of the file is visible in the main screen section.

    5. This will open RStudio, and you can go ahead with your analysis. 
    Screenshot of RStudio session in Terra with example standard output code in the entrypoint.out section at left, an empty environment section at the top right, and teh environment.out under files in the bottom right.

Saving RStudio analyses (autosave and more)

You can save any code you write in your Terra RStudio instance by creating a new file of the appropriate file type. Running code in the console is good for testing, but to export your code or save it to another location, you must create and save a file containing the code explicitly.

You can save your work as an R-Markdown (.Rmd) file from the File menu at the top of your RStudio instance.

Screenshot of RStudio instance in a Terra workspace with the File menu dropdown expanded. The save as option is visible at the bottom of the dropdown.

Your files will display under Your Analyses in your workspace's Analyses tab.

Screenshot of workspace Analyses tab with HellowWorld RMarkdown file in the Name column of the Your Analysis section and the R logo under the application column.

Autosave

To ensure you don't lose your work, Terra autosaves files every 10 seconds (by default) to workspace storage (Google Bucket). 

Autosave details

  • Autosave syncs your work to workspace storage and your workspace's Persistent Disk in the background (changes persist).
  • When the file is open, its autosave status is indicated by the color and content below the RStudio logo at the top left of the screen.
  • To change the default autosave period, open the file and go to Options > Settings > Save.

Running long calculations?

Note that Terra will autosave if there is no activity in the browser, regardless of whether the VM is actively running calculations. If you are running a long calculation with autopause enabled, this may lead to Terra saving and pausing your work before the process has terminated (although it may also autosave the work you've done already).

If you are running a long calculation and don't want to babysit it, you may want to adjust the autopause so that it does not time out. See the article on How to adjust Cloud Environment autopause for more information.

Deleting unwanted .Rmd files

Delete all files in Terra (Analyses tab)When you finish your analysis and want to delete extra .Rmd files, delete them from the Analyses tab in Terra, not the RStudio instance. This keeps Terra from overwriting deleted files with an autosaved version.

Was this article helpful?

1 out of 2 found this helpful

Comments

2 comments

  • Comment author
    Peter van Galen

    For the **Autosave** section:

    1) Are .R files also saved every 10 seconds?

    2) Do you mean I should increase the autopause time for long calculations? Why is this related to autosave?

    1
  • Comment author
    Derek Caetano-Anolles

    Thanks for your comments, Peter. I've updated the document accordingly.

    But to answer your questions, yes — Terra also autosaves R files every 10 seconds.

    Regarding autopausing, autosaving and autopausing are unrelated to the length of the calculations you are running -- in other words, if you know that your process will take a long time, Terra might save and pause it before it actually completes. That's not an ideal scenario for most, I imagine, so there are ways to adjust the timings here.

    You are right, in that the original wording of the article did not make it clear why this was related to autosaving. It should be better now. Thanks again for the feedback :)

    1

Please sign in to leave a comment.