Upload a File From R Studio to Github

This tutorial teaches you to create R Markdown documents with RStudio and publish them via GitHub, using GitHub Pages.

RStudio is a popular integrated development environs for R. It integrates the tools you use with R into a single environment. GitHub Pages allows you to host websites directly from your GitHub repository.

In this tutorial, you lot will learn how to:

  • Create a new repository.
  • Piece of work with your repository on your local automobile using Git and RStudio.
  • Use the GitHub.com website or GitHub Enterprise to complete the GitHub workflow.
  • Publish and share your R Markdown documents using GitHub Pages.

Prerequisites

  • For this tutorial you will need an account on GitHub.com or GitHub Enterprise.
  • If y'all are new to Git, GitHub and GitHub Pages it is recommended to complete the GitHub Pages from the control-line course start.
  • Some programming cognition with R will exist helpful but is non required.

Install Git and RStudio

For this tutorial you will utilise Git and RStudio to work with your GitHub repository.

  1. Download and install Git.
  2. Download and install RStudio. (one.1.383 or college).
  3. Open up RStudio.

Create the remote repository on GitHub

Now that you lot have what you need installed locally, let's create the repository that will hold your new website.

  1. On GitHub.com, create a new repository.

Note: if your organization uses GitHub Enterprise you can likewise create the repository there.

  1. Proper name your repository cars. You can use a dissimilar name.
  2. Enter a description for your repository.
  3. Choose Public visibility.
  4. Select Initialize this repository with a README.
  5. Click Add .ignore and select R.
  6. Click Create repository.

Clone the repository with RStudio

After yous've created a repository on GitHub (the remote repository), the side by side step is to clone it to your local environment.

  1. On GitHub, navigate to the Code tab of the repository.
  2. On the right side of the screen, click Clone or download.
  3. Click the Copy to clipboard icon to the right of the repository URL.
  4. Open up RStudio on your local environment.
  5. Click File, New Project, Version Command, Git.
  6. Paste the repository URL and enter TAB to move to the Project directory name field.
  7. Click Create Projection.

Create an R Markdown certificate in RStudio

Now that yous have a local copy of the repository, permit's add an R Markdown certificate to your project.

  1. In RStudio click File, New File, R Markdown.
  2. Choose HTML output equally default output.
  3. Click File, Relieve to relieve the document.
  4. Enter speed-and-distance and click Save. rstudio-editor

Commit and push the changes to GitHub

After you lot have created the R Markdown document and finished making your changes, it is time to commit them.

  1. In RStudio click the Git tab in the upper right pane.
  2. Click Commit.
  3. In the Review changes view, bank check the staged box for all files.
  4. Add together a commit message, for example Add together initial speed and distance report.
  5. Click Commit.
  6. Click the Pull push to fetch whatever remote changes.
  7. Click the Push button button to push your changes to the remote repository.
  8. On GitHub, navigate to the Code tab of the repository to run into the changes.

Create local branches with Git

Let'south make a couple of more changes in your project using the steps of GitHub Flow. As RStudio currently does not back up local branches very well, we volition utilise Git from the command-line in RStudio.

  1. In RStudio click the Concluding tab in the lower left pane. The Terminal tab is next to the Console tab. rstudio-terminal

Note: if you cannot observe the Last tab, check if you use RStudio version ane.ane.383 or higher. Click Help, Near RStudio to bank check the electric current version.

  1. Create a new branch. Replace <Co-operative-Proper name> with a descriptive name, for example speed-and-distance-report:

                  git branch <BRANCH-NAME>                          
  2. Bank check your repository's status:

                  git condition                          

    Notice that although yous created a new branch, y'all are still checked out to master, as indicated by the in-line response from Git.

  3. Check out to your new branch:

                  git checkout <BRANCH-Proper noun>                          
  4. Verify that you are now checked out to your new branch:

                  git status                          

Make local changes with Git

Permit's generate the HTML output in a separate directory called docs. To do this we add a part in the heading of the R Markdown document to 'knit' the output in the desired output directory.

  1. In RStudio open up speed-and-distance.Rmd and add the following lines in the heading nether the title field:
          knit: (function(input_file, encoding) {     out_dir <- 'docs';     rmarkdown::render(input_file,       encoding=encoding,       output_file=file.path(dirname(input_file), out_dir, 'index.html'))})        
  1. Click File, Salvage to salve the changes.
  2. Click Knit in the document pane for speed-and-distance.Rmd.

Commit local changes with Git

After you lot have created the HTML output, it is time to commit the changes.

  1. Determine your file'south condition. Call back that git status allows u.s.a. to see the status of the files on our branch at any given time. Your file is listed under the heading Untracked files:

                  git status                          
  2. Add your file to the staging area so it's prepared to become part of the next commit:

                  git add .                          
  3. See your file'southward current status. Your file is at present listed under the heading Changes to be committed. This tells us that the file is in the staging expanse. It also indicates this is a new file:

                  git status                          
  4. Commit your file. Supplant <COMMIT-Message> with a log message describing the changes, for example Knit output to a docs folder. A commit tells Git to collect all of the files in the staging area and shop them to version command as a single unit of piece of work:

                  git commit -m "<COMMIT-Bulletin>"                          
  5. Come across the history of commits:

                  git log --oneline                          
  6. See the changes between the master branch and the electric current co-operative (HEAD):

                  git diff --stat --summary master..<BRANCH-NAME>                          

Open a pull request on GitHub

Now that you accept made some local commits, information technology is fourth dimension to send your changes to the remote re-create of your repository on GitHub and create a Pull Request.

  1. Push the changes to the remote repository:

                  git push button -u origin <Co-operative-NAME>                          
  2. Create a Pull Request on GitHub.

  3. Fill out the body of the Pull Request with information virtually the changes you're introducing.

Merge your pull asking on GitHub

Since this is your repository, you probably don't take anyone to collaborate with (yet). Go ahead and merge your Pull Request at present.

  1. On GitHub, navigate to the Pull Request that you just opened.
  2. Scroll down and click the big green Merge Pull Request button.
  3. Click Ostend Merge.
  4. Delete the branch <Branch-NAME>.

Create the pages site

This tutorial is going to employ GitHub Pages to publish the HTML output. To initialize GitHub Pages nosotros need to perform a few more steps:

  1. In your repository, click the Settings tab.
  2. Coil downward to the GitHub Pages section.
  3. Under Source, select master co-operative /docs folder. pages-configuration
  4. Click Relieve to save the changes.
  5. Click the generated GitHub Pages URL to view the rendered R Markdown document.

Note: GitHub Pages sites are always public when hosted on GitHub.com. If you want to share a site with a select number of people you can utilise Jekyll Auth. On GitHub Enterprise users need to cosign to access GitHub Pages sites when private manner is enabled.

Update local repository

After you merge your Pull Request, you volition need to update your local copy of the repository.

  1. In the RStudio Last pane, type:

                  git checkout master                          
  2. Type:

                  git pull                          
  3. Delete the local branch :

                  git branch -D <Co-operative-Name>                          
  4. Meet the history of your commits in a graph:

                  git log --oneline --graph --all                          

You can also view the history of your commits in RStudio. Click Commit in the Git pane to open the Review Changes panel and then click History.

Add together welcome page, theme and navigation

Permit'south add a welcome page, theme and navigation to allow you to publish a collection of R Markdown documents.

  1. First create a new branch. Again supersede <BRANCH-NAME> with a descriptive proper noun, for example add together-theme-and-navbar:

                  git checkout -b <BRANCH-Proper noun>                          
  2. Add a file _site.yml with the following contents:

          name: "cars"   output_dir: "docs"   navbar:     title: "Cars"     left:     - text: "Home"         href: index.html     - text: "Speed and Distance"         href: speed-and-distance.html   output:     html_document:       theme: cosmo        
  1. Add a new R Markdown document index.Rmd. This is your welcome page.

  2. Open speed-and-altitude.Rmd and remove the knit and output fields from the heading. The heading volition now await similar this:

          ---   title: "Speed and Distance"   ---        
  1. Salve the changes.

  2. Open the Console in the left bottom pane and return the site using the post-obit control:

          rmarkdown::render_site()                  
  1. Commit the local changes with Git:
                  git status   git add .   git commit -1000 "Add together home page, navigation and theme"            

Open a pull request

Now that y'all take added the dwelling house page and navigation, it is time to send your changes to the remote copy of your repository on GitHub and open up a new pull request.

  1. Push the changes to the remote repository:

                  git push -u origin <BRANCH-NAME>                          
  2. Open a Pull Asking on GitHub.

  3. Become ahead and merge your Pull Request.

  4. View your updated site. The site should look similar to this image.

    speed-and-distance
  5. Add the GitHub Pages URL to the repository description to make information technology easier to discover.

If you tin can't remember the GitHub Pages URL y'all tin e'er visit the URL in the GitHub Pages section on the settings page.

Congratulations! 🎉

You lot have completed the GitHub workflow with RStudio and added a GitHub Pages site to your projection to publish your rendered R Markdown documents.

Links

  • The R Markdown Websites article on the R Markdown website is a good resources to build GitHub Pages websites that host collections of R Markdown documents.
  • Employ GitHub Desktop if yous prefer to utilize a graphical user interface rather than typing Git commands in the terminal when working with branches in RStudio.

oakescausbableche.blogspot.com

Source: https://resources.github.com/github-and-rstudio/

Related Posts

0 Response to "Upload a File From R Studio to Github"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel