R markdown blog template
This article is originally published at http://lcolladotor.github.io/
This blog post is mostly for myself but maybe it’s useful to others. It contains my current R markdown blog template. I initially posted this as a question at StackOverflow. Then I read how much a burden we put in Yihui Xie and decided that my current setup (copy-pasting) works just fine. In any case using blogdown
with the RStudio IDE is much simpler than what I used to do in the past with jekyll or with even my prior setup with blogdown.
Bibliography setup
First I define the citation information I’ll need. By the way, I used FAQ 7 for showing the R code chunk.
```{r bibsetup, echo=FALSE, message=FALSE, warning=FALSE}
## Load knitcitations with a clean bibliography
library('knitcitations')
cleanbib()
cite_options(hyperlink = 'to.doc', citation_format = 'text', style = 'html')
bib <- c('knitcitations' = citation('knitcitations'),
'blogdown' = citation('blogdown')[2])
```
Post content
This is where I typically start to edit since the bibliography chunk is hidden.
R image
```{r 'plot'}
## This will create the /post/*_files/ directory
## where you can later copy the non-R images you want to use
## in the blog post
plot(1:10, 10:1)
```
Note that I modified the YAML portion of the post to set the figure width and height. You can also include a table of contents if you want, though it affects the summary of the post. Check the output format section of the blogdown
book for more details (Xie, Hill, and Thomas, 2017), including differences between .Rmd
and .Rmarkdown
files. Note that you can also use a _output.yml
file as described there.
output:
blogdown::html_page:
toc: no
fig_width: 5
fig_height: 5
Custom image syntax
Here I remind myself of different ways I can include external images. Check blogdown issue 239 for some background information.
Markdown syntax for custom image:
![](/post/2018-02-17-r-markdown-blog-template_files/LIBD.jpg)
HTML syntax for centering image, including a link, and re-sizing the image to a fix width of 200 px.
<center>
<a href="http://lcolladotor.github.io/"><img alt = 'some website' width='200' src='/post/2018-02-17-r-markdown-blog-template_files/LIBD.jpg' /></a>
</center>
Reproducibility
## Reproducibility info
library('devtools')
options(width = 120)
session_info()
## Session info ----------------------------------------------------------------------------------------------------------
## setting value
## version R version 3.4.3 (2017-11-30)
## system x86_64, darwin15.6.0
## ui X11
## language (EN)
## collate en_US.UTF-8
## tz America/New_York
## date 2018-03-10
## Packages --------------------------------------------------------------------------------------------------------------
## package * version date source
## backports 1.1.2 2017-12-13 CRAN (R 3.4.3)
## base * 3.4.3 2017-12-07 local
## bibtex 0.4.2 2017-06-30 CRAN (R 3.4.1)
## blogdown 0.5.10 2018-03-10 Github (lcolladotor/blogdown@471b086)
## bookdown 0.7 2018-02-18 cran (@0.7)
## colorout * 1.2-0 2018-02-19 Github (jalvesaq/colorout@2f01173)
## compiler 3.4.3 2017-12-07 local
## datasets * 3.4.3 2017-12-07 local
## devtools * 1.13.5 2018-02-18 CRAN (R 3.4.3)
## digest 0.6.15 2018-01-28 CRAN (R 3.4.3)
## evaluate 0.10.1 2017-06-24 CRAN (R 3.4.1)
## graphics * 3.4.3 2017-12-07 local
## grDevices * 3.4.3 2017-12-07 local
## htmltools 0.3.6 2017-04-28 CRAN (R 3.4.0)
## httr 1.3.1 2017-08-20 CRAN (R 3.4.1)
## jsonlite 1.5 2017-06-01 CRAN (R 3.4.0)
## knitcitations * 1.0.8 2017-07-04 CRAN (R 3.4.1)
## knitr 1.20 2018-02-20 cran (@1.20)
## lubridate 1.7.3 2018-02-27 CRAN (R 3.4.3)
## magrittr 1.5 2014-11-22 CRAN (R 3.4.0)
## memoise 1.1.0 2017-04-21 CRAN (R 3.4.0)
## methods * 3.4.3 2017-12-07 local
## plyr 1.8.4 2016-06-08 CRAN (R 3.4.0)
## R6 2.2.2 2017-06-17 CRAN (R 3.4.0)
## Rcpp 0.12.15 2018-01-20 CRAN (R 3.4.3)
## RefManageR 0.14.20 2017-08-17 CRAN (R 3.4.1)
## rmarkdown 1.9 2018-03-01 cran (@1.9)
## rprojroot 1.3-2 2018-01-03 CRAN (R 3.4.3)
## stats * 3.4.3 2017-12-07 local
## stringi 1.1.6 2017-11-17 CRAN (R 3.4.2)
## stringr 1.3.0 2018-02-19 cran (@1.3.0)
## tools 3.4.3 2017-12-07 local
## utils * 3.4.3 2017-12-07 local
## withr 2.1.1 2017-12-19 CRAN (R 3.4.3)
## xfun 0.1 2018-01-22 CRAN (R 3.4.3)
## xml2 1.2.0 2018-01-24 CRAN (R 3.4.3)
## yaml 2.1.18 2018-03-08 cran (@2.1.18)
References
Citations made with knitcitations
(Boettiger, 2017) and blog built using blogdown
(Xie, Hill, and Thomas, 2017).
## Chunk normaly with options: results = 'asis', echo = FALSE, cache = FALSE
## Print bibliography
bibliography(style = 'html')
[1] C. Boettiger. knitcitations: Citations for ‘Knitr’ Markdown Files. R package version 1.0.8. 2017. URL: https://CRAN.R-project.org/package=knitcitations.
[2] Y. Xie, A. P. Hill and A. Thomas. blogdown: Creating Websites with R Markdown. ISBN 978-0815363729. Boca Raton, Florida: Chapman and Hall/CRC, 2017. URL: https://github.com/rstudio/blogdown.
Thanks for visiting r-craft.org
This article is originally published at http://lcolladotor.github.io/
Please visit source website for post related comments.