HumanitaRian useR group

4 minutes read


Creating Websites with R Markdown is easy and can be done directly R Blogfown package. This is how this site is built.

The website is generated from R Markdown documents (R is optional, i.e., you can use plain Markdown documents without R code chunks). This brings a huge amount of benefits, especially if your website is related to data analysis or (R) programming. Being able to use Markdown implies simplicity and more importantly, portability (e.g., you are giving yourself the chance to convert your blog posts to PDF and publish to journals or even books in the future). R Markdown gives you the benefits of dynamic documents — all your results, such as tables, graphics, and inline values, can be computed and rendered dynamically from R code, hence the results you present on your website are more likely to be reproducible.

R Markdown

Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00
fit <- lm(dist ~ speed, data = cars)
fit
## 
## Call:
## lm(formula = dist ~ speed, data = cars)
## 
## Coefficients:
## (Intercept)        speed  
##     -17.579        3.932

Including Plots

You can also embed plots. See Figure 1 for example:

par(mar = c(0, 1, 0, 1))
pie(
  c(280, 60, 20),
  c('Sky', 'Sunny side of pyramid', 'Shady side of pyramid'),
  col = c('#0292D8', '#F7EA39', '#C4B632'),
  init.angle = -50, border = NA
)
A fancy pie chart.

Figure 1: A fancy pie chart.

Blog post writing

This is a post written in plain Markdown (*.md) instead of R Markdown (*.Rmd). The major differences are:

  1. You cannot run any R code in a plain Markdown document, whereas in an R Markdown document, you can embed R code chunks (```{r});
  2. A plain Markdown post is rendered, and an R Markdown document is compiled by rmarkdown and Pandoc.
blogdown::new_post("Post Title", rmd = FALSE)

Blogdown helps you to create blog posts and other types of web content using the RMarkdown language. Those 8 functions are the key ones:

  • build_site() : Compiles all .Rmd files into Hugo-readable HTML & builds the site
  • html_page() : Renders .Rmd file into Hugo-readable HTML
  • hugo_cmd() : Allows you to run Hugo commands
  • install_hugo() : Downloads the appropriate Hugo files to your computer to allow site generation
  • install_theme() : Downloads the specified theme from GitHub
  • new_content() : Generates a new file in your working directory
  • new_site() : Creates the environment necessary for a new site
  • serve_site() : Allows you to preview a working version of your site

Submiting to the platform

You will need to use GitHub GitHub is powered by Git, a command-line version-control system. basic vocab is explained below:

  • Repository : When you make an account on Github the first thing you’ll want to do is make a repository (or repo). This is the place to store all of your files for a given project.
  • Forking : Say you really like someone else’s project on GitHub and you’d like to make a copy of it on your account to adjust however you’d like? Well, that process is called forking. To do it, find a repo that you like and click the ’ fork ’ button in the right hand corner.
  • Branch : This is a “parallel version” of a repo that you can adjust without impacting the original repo.
  • Remote : The copy of your files that reside on GitHub.com
  • Local : The copy of your files that reside on your computer
  • Commit : A change to a file, usually submitted with a message from you to indicate what was changed
  • Push : Once you commit changes on your local files, you want to send (or push) them to your remote repo, making them available for others.
  • Pull : If multiple people are working in your remote repo, they may have made a change that is not reflected in your local version. You can pull the newest version down to your computer to work on it.
  • Subtree : This is a repo inside of a repo. More on this later.

Simply fork the main repository - open the [vigie-blogdown.R] script and start creating your Rmd.

An indepth tutorial is presented here

comments powered by Disqus