How to Upload R Script to Github

Connect RStudio to Git and GitHub

Here nosotros verify that RStudio can effect Git commands on your behalf. Assuming that you've gotten local Git to talk to GitHub, this means you'll also be able to pull from and push to GitHub from RStudio.

In later chapters and in live workshops, nosotros revisit these operations with much more explanation.

If you lot succeed here, your set up is DONE.

Prerequisites

We assume the following:

  • You've registered a free GitHub account (chapter 4).
  • You lot've installed/updated R and RStudio (chapter 5).
  • You've installed Git (affiliate 6).
  • Yous've introduced yourself to Git (chapter 7).
  • You lot've confirmed that you tin can button to / pull from GitHub from the command line (affiliate 11).

You volition also need a exam repository on GitHub.

If you just completed the previous chapter, Connect to GitHub, that volition be perfect! However, I encourage you to delete the local repository, so you lot can experience how we use RStudio to clone it and get a local copy. Delete the binder corresponding to the local repo any way you similar. It'due south merely a regular directory on your computer. Here's how to practice that in the beat out, if current working directory is myrepo:

            cd .. rm -rf myrepo/          

If you don't take a suitable test repository on GitHub, follow the instructions in the next section.

Brand a repo on GitHub

Go to https://github.com and make certain you are logged in.

Almost "Repositories", click the big light-green "New" button. Or, if you lot are on your own profile page, click on "Repositories", and then click the big dark-green "New" button.

How to fill up this in:

  • Repository template: No template.
  • Repository proper noun: myrepo or any you wish (we'll delete this soon).
  • Description: "Repository for testing my Git/GitHub setup" or similar. It's nice to accept something here, so y'all'll encounter it appear in the README.
  • Public.
  • Initialize this repository with: Add a README file.

Click the large green button that says "Create repository".

At present click the big dark-green push button that says "<> Lawmaking".

Copy a clone URL to your clipboard. If y'all're taking our default communication, copy the HTTPS URL. Just if you're opting for SSH, then brand sure to re-create the SSH URL.

Selecting an HTTPS vs SSH URL on GitHub

Clone the test GitHub repository to your computer via RStudio

In RStudio, offset a new Projection:

  • File > New Project > Version Control > Git. In "Repository URL", paste the URL of your new GitHub repository. Information technology will be something like this https://github.com/jennybc/myrepo.git.
    • Do you lot Non see an choice to get the Project from Version Control? Restart RStudio and try once more. Withal no luck? Go to chapter thirteen for tips on how to help RStudio find Git.
  • Take the default project directory proper noun, east.1000.myrepo, which coincides with the GitHub repo name.
  • Accept charge of – or at least discover! – where the Project volition exist saved locally. A common rookie fault is to have no idea where you are saving files or what your working directory is. Pay attention. Be intentional. Personally, I would do this in ~/tmp.
  • I suggest you check "Open in new session", as that's what you'll ordinarily do in real life.
  • Click "Create Project".

You should discover yourself in a new local RStudio Projection that represents your test repo on GitHub. This should download the README.md file from GitHub. Look in RStudio's file browser pane for the README.md file.

Make local changes, save, commit

From RStudio, modify the README.physician file, e.g., by adding the line "This is a line from RStudio". Save your changes.

Commit these changes to your local repo. How?

From RStudio:

  • Click the "Git" tab in upper right pane.
  • Check "Staged" box for README.doctor.
  • If you're not already in the Git popular-up, click "Commit".
  • Type a message in "Commit message", such as "Commit from RStudio".
  • Click "Commit".

Push your local changes online to GitHub

Click the green "Push" button to send your local changes to GitHub.

You lot should not experience a credential challenge, since ane of the pre-requisites was successfully pushing to GitHub from the command line (chapter eleven). RStudio's Git pane just exposes a specific subset of command line Git and therefore once your credentials work in the shell, they should work in RStudio. If y'all do experience a credential challenge, that suggests you lot should have a wait at the troubleshooting suggestions for your called protocol, either HTTPS or SSH.

Ostend the local change propagated to the GitHub remote

Go back to the browser. I assume we're still viewing your new GitHub repo.

Refresh.

You should run into the new "This is a line from RStudio" in the README.

If you click on "commits", you should encounter one with the message "Commit from RStudio".

If you have made information technology this far, you are DONE with set upward. Congratulations!

Clean up

Quit the RStudio instance that's open up to your test Project / Git repo.

Delete the local repo any way you lot like. It's but a regular directory on your computer.

Hither's how to do that in the shell, if current working directory is myrepo:

            cd .. rm -rf myrepo/          

In the browser, go to your repo'due south landing folio on GitHub. Click on "Settings".

Scroll down, click on "delete repository," and practice every bit it asks.

sharpgess1961.blogspot.com

Source: https://happygitwithr.com/rstudio-git-github.html

0 Response to "How to Upload R Script to Github"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel