My aim is a XKCD-alike blog for publishing r - knitr posts. I use hugo as generator. The papercss hugo theme which uses papercss provides a nice style sheet.

Todo use xkcd plot function in R.

The repo is on github.

Guides

to get you started.

Initial Setup

clone

The master branch contains also the github page published here. You can make an empty start by cloning the plain branch:

git clone --single-branch --branch plain https://github.com/bdcaf/r-hugo-papercss-template.git

local setup

Many actions are run as make actions.

You can do to all actions doing

make setup

read more..


Create Post

Create a post using

hugo new --kind r-bundle post/mytitle

For now this will create a skeleton directoru under content/post/mytitle/. This content will contain a file index.md which will be overwritten. The interesting file is source.md - it will get special treatment as it is ignored in the settings. Without this ignoring it would show up twice.

It is a hugo specific that it will only fill out templates with extension .md. I put in a modeline for vim to set the filetype to rnoweb.

read more..



Tips

  • the contents of docs/ is deleted before building the site. If this is not done no longer used files will build up in there. Should you need to keep files put them in the static directory.

  • I dislike the way hugo truncates posts automatically for summary.
    Manually truncating by placing <!–more–> assures the head is rendered nicely. For short posts one can just put it at the and assure they are rendered fully.

read more..


Posts

Some exemplary posts here.

Test Blogdown

Let’s do a little R with the cars dataset.

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
with(cars, plot(speed, dist))
a cars plot

The source is index.Rmd.


use custom render

In knitr/R/hooks-md.R there is a custom function render_jekyll.
I wrote a similar one for hugo that makes figure shortcodes.
Then I could remove the perl from the makefile.
This was a dirty hack which I am happy to got rid of. Suppose I will add some more shortcodes in the future.

For now see some examples here:

I use some examples from Producing Simple Graphs with R.

# Define the cars vector with 5 values
cars <- c(1, 3, 6, 4, 9)

# Graph the cars vector with all defaults
plot(cars)

float-right fig.cssClass
Figure one is supposed come right of this.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

read more..


slides

This is render from 009-slides % Writing beautiful and reproducible slides quickly % Yihui Xie % 2012/04/30 Why after you finished typing \documentclass{beamer} and \title{}, I have finished my first slide with markdown far fewer commands to remember, e.g. to write bullet points, just begin with a dash “-” instead of \begin{itemize} and \item; how things can be simpler? I know you want math to show you are a statistician, e.

read more..




use devtools

Although a blog post is not a R package the devtools package provides some useful tools. But who knows maybe a package will sprout from a post.

plain devtools

Provides some functions to create bundled data.
I like to use devtools::load_all() to load up all R functions from the R subdirectory.

I placed a simple function under R/hello_world.R

read more..


minimal R Markdown example

This is a render from knitr examples. A minimal R Markdown example A quote: Markdown is not LaTeX. To compile me, run this in R: library(knitr) knit(‘001-minimal.Rmd’) See output here. code chunks A paragraph here. A code chunk below (remember the three backticks): 1+1 ## [1] 2 .4-.7+.3 # what? it is not zero! ## [1] 5.551115e-17 graphics It is easy. plot(1:10) plot of chunk unnamed-chunk-2 hist(rnorm(1000)) plot of chunk unnamed-chunk-2 inline code Yes I know the value of pi is 3.

read more..