Here describe how we can host websites on GitHub pages. To do that, we need to install Git and create a GitHub account. Some introduction resources about Git and GitHub are the following:

1 R projects

R projects allows us to keep all files associated with a project together.

Chapter 8.4 RStudio projects: https://r4ds.had.co.nz/workflow-projects.html

2 Creating a GitHub account

3 Installing Git

To create projects from Git repositories you should install Git and then restart RStudio.
Note that if Git is installed and not on the path, then you can specify its location using the Options dialog.
https://support.rstudio.com/hc/en-us/articles/200532077?version=1.4.1103&mode=desktop

Google “installing git for windows”
Enter https://git-scm.com/download/win
Click here to download manually (git 64 bit)

4 Create an R project in GitHub and RStudio

To create an R project, first we make a GitHub repo, and then we create an RStudio project:

https://happygitwithr.com/new-github-first.html#make-a-repo-on-github-1

4.1 Make a repository on GitHub

  • Click the green New repository button. Or, if you are on your own profile page click Repositories and then the green New button.

  • Enter the repository name and description, public/private and Initialize this repository with a README.

  • Click the big green button Create repository.

  • Copy the HTTPS clone URL to the clipboard by going to the main page of the new repository, and clicking Code Clone button (it will be something like https://github.com/username/reponame.git).



4.2 Make a new RStudio project via git clone

  • In RStudio, start a new project with File > New Project > Version Control > Git. In the Repository URL paste the URL of the new GitHub repo (it will be something like https://github.com/username/reponame.git).

  • Click Create project to create a new directory which will be a directory on the computer, a Git repository linked to a remote GitHub repo, and an RStudio project.

By doing this, the remote GitHub repo is added as a remote for the local repo and the local master branch is now tracking master on GitHub. This means we are set up to push and pull.



4.3 Add content

Note that after creating the R Project and adding content, we may need to close the project and reopen it in order to RStudio recognizes the project (as a website, blogdown, etc.) and show the appropriate build tools.

4.4 Make local changes, save, commit and push

Create the R Markdown document, commit and push

git status
git add .
git commit -am "initial commit"
git push

5 Sharing an HTML document online

To display the HTML online using GitHub follow these steps:

  • Name the .Rmd file as index.Rmd. Knit it to have a index.html file
  • Push the changes to the GitHub repo
  • On the GitHub online repo go to Settings > GitHub Pages > Source > Master Branch > Save.
  • Wait a little, the HTML file will be available at username.github.io/reponame