RStudio Cloud is a new service offered by RStudio that allows users to use R and RStudio online and collaborate on projects with other users through the RStudio Cloud website. With RStudio Cloud, all of your projects - including all corresponding R files - are stored in the cloud on RStudio’s server, making them available to you online anytime and anywhere, no matter what computer you’re using.
Using RStudio with version control will make collaboration smoother by keeping track of changes in Github’s source code repository. Not only will your code be accessible on Github, but every change will also be logged and various versions of the same file can be created so that you can easily view and incorporate changes made by collaborators or go back to a previous version if a mistake is made.
Read more about version control here.
* This guide assumes basic knowledge of Github & no prior knowledge of Git
1) RStudio Cloud Setup
1. Create an empty repository in Github
2. Create a new project in RStudio Cloud - Go to RStudio Cloud and click the arrow next to “New Project.” From the dropdown menu, select “New Project from Git Repo.”
Copy and paste the URL from your Github repository into the prompt box. Now your RStudio Cloud project is connected to your Github repository. Any changes made in RStudio Cloud can be reflected in Github (Scenario A), and vice versa (Scenario B).
Scenario A: Pushing changes in RStudio Cloud to Github
1. Configure git in RStudio Cloud
a. Click on the Terminal tab on the bottom panel within your RStudio Cloud project.
b. Within Terminal, type the following commands but replacing firstname.lastname@example.org with your actual email address, and Your Name with your actual name within the quotation marks:
This will log any changes you make under your specific user identity and keep track of who made what edits.
2. Commit changes in Git
a. Save all files in RStudio Cloud that you’ve edited, if you haven’t already.
b. On the right panel, go to the tab on the far right that says “Git.” In that tab, you should see the files that you edited and saved. Click the box under “Staged” to select the file you want to update in Github.
c. Click the “Commit” button on the toolbar. This basically saves the changes in Git so that you can push them to Github.
d. A window will pop up showing the changes you’ve made. Put in a commit message, which is a brief description of the changes you’ve made, and click Commit.
3. Push changes to Github
a. Choose the branch that you would like to commit the changes to by selecting from the drop-down menu, and then click the green arrow up Push button. (This can also be done on the main RStudio Cloud window on the toolbar of the Git tab.)
b. A pop-up window will ask you to put in your username and password for Github. Follow the instructions as prompted.
c. Optional: You can go to Github and check your Github repository to confirm that your changes were successfully pushed to Github.
4. OPTIONAL: Avoid having to type in username and password every time you want to push an edit to Github
a. On the top toolbar of your RStudio Cloud project, click “Tools” and select “Global Options…” from the dropdown menu
b. From the list of options on the left side of the pop-up window, select Git/SVN.
c. Click the button “Create RSA Key.” Another pop-up prompt will appear; click “Create.” Click View public key and copy the key to the clipboard.
d. Navigate to Github and go to your profile by clicking on the top right corner where your avatar is and selecting “Your profile” from the drop-down menu. On the left side of your profile page, select “Edit profile.”
e. Go to “SSH and GPG keys” and click the “New SSH key” button. Give your key a title and paste the key into the Key textbox. Then click “Add SSH key”
f. Navigate back to your RStudio Cloud project and go to the Terminal tab on the bottom panel of your window. In the terminal, type the following, but replace YourUsername and YourRepo with your Github username and Github repository name (as it is written in your Github repository URL):
Scenario B: Pulling changes from Github to RStudio Cloud
1. Commit changes in Github. This is done via a form at the bottom of your file in Github - fill out a brief description of the changes you’re committing, and select “Commit directly to the master branch.” Then click “Commit changes”.
2. Pull changes from Github.
a. In RStudio Cloud, go to your corresponding RStudio Cloud project.
b. On the right panel, go to the tab on the far right that says “Git.” On the toolbar, click the blue arrow pointing downwards. This will pull the changes you made from Github into RStudio Cloud. The file should automatically be updated after you click.