How to Build a Website in RMarkdown

1 Intro

Statistics is the combination of art and mathematics, so delivering our findings effectively and efficiently is the key to being a great statistician. RMarkdown is a fantastic tool for demonstrating our statistical results to our audiences. Still, it has limitations on transmitting, so posting findings on a personal website or blog could be an excellent alternative medium.

2 Pre-requisites

  • R (required for this tutorial)
  • RStudio (recommended, but you can also use Quarto or simply with R console)
  • Github account (required)
  • Install Git from GitHub (required)

3 R/RStudio

3.1 install blogdown package in two ways

3.1.1 CRAN (relatively realiable)

install.packages("blogdown")

3.1.2 Github (updates faster)

remotes::install_github('rstudio/blogdown')

3.2 initialize your website settings

flowchart

If you don’t like the default theme, you can use blogdown::install_theme() to download alternative themes from Hugo Themes.

3.3 live view your progress

liveview

usethis::create_github_token() # generate a token in GitHub site
gitcreds::gitcreds_set() # link the token with your gitclient
usethis::use_git() # initialise a git repository
usethis::use_github() # connect a local repo with GitHub

4 Netlify

Netlify is a website that can host your website from GitHub. Click GitHub login, and your can use your GitHub account as your Netlify credentials.

netlifyflow

After deploying your site, you will see a page below where you can setup your custom domain name.

netlify5

5 Create a post

  • Click “New Post” (under Section 3.3 “Serve Site” button) to generate a new post markdown window.

  • Click “Insert image” (still under Section 3.3 “Serve Site” button) to insert an image. Or simply create a folder called “images” and drag your images to the “images” folder. Use command <img src="images/image_name.png"/> to call it in the markdown file.

  • Commit a post:

    • Click “Diff” in the right-up corner
    • Check all the boxes (it means all your changed files)
    • Add commit messages (for you to track your change log)
    • Click Commit - Click “Push”

6 References

  1. blogdown: Creating Websites with R Markdown
  2. w3schools for useful html code
Yan Zhang
Yan Zhang
Associate Research Scientist

My research interests include high-dimensional cancer genomics, metagenomics and causal inference.