<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/how-to-set-up-your-own-r-blog-with-github-pages-and-jekyll-bootstrap/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://shiring.github.io/blogging/2016/12/04/diy_your_own_blog"> Shirin's playgRound</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h3>This post is in reply to a request: How did I set up this R blog?</h3>
<p>I have wanted to have my own R blog for a while before I actually went ahead and realised this page. I had seen all the cool things people do with R by following <a target="_blank" rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers</a> and reading their newsletter every day!</p>
<p>While I am using R every day at work, the thematic scope there is of course very bioinformatics-centric (with a little bit of Machine Learning and lots of visualization and statistics), I wanted to have an incentive to regularly explore other types of analyses and other types of data that I don’t normally work with. I have also very often benefited from other people’s published code in that it gave me ideas for my own work and I hope that sharing my own analyses will inspire others as much as I often am by what can be be done with data.</p>
<p>Moreover, since I’ve started my R blog, I’ve very much enjoyed interacting more with other R-bloggers and R users and getting valuable feedback. I definitely feel more part of the community now that I’m an active contributor!</p>
<p></p>
<p>In this post, I will describe how I go about publishing R code and its output to my blog. I will not go into detail on how to customize your page but only give a quick introduction to setting up a blog with Github pages and JekyllBoostrap. I will focus on how to write content with RMarkdown and RStudio.</p>
<p></p>
<h1>Setting up Github pages</h1>
<p>I decided to host my blog on Github pages because I was already used to working with Github (it’s where I store my <a target="_blank" rel="nofollow" href="https://shiring.github.io/rna-seq/microarray/2016/09/28/exprAnalysis">exprAnalysis R package</a>).</p>
<p>Setting up your own <a target="_blank" rel="nofollow" href="https://pages.github.com/">Github page</a> is free and very easy! All you need is a Github account. On Github you need to create a new repository called “<em>username</em>.github.io”” (substitute <em>username</em> for your Github user name, in my case: ShirinG.github.io).</p>
<p>I set up the rest via the terminal interface:</p>
<ul>
<li>go to the folder where your repository should live (in this example called “<em>Test</em>”)</li>
<li>clone the repository and change to its directory</li>
<li>pull from Github to make sure everything is synchronized and up to date between your computer and Github</li>
</ul>
<div>
<pre><code><span>cd </span>Home/Documents/Test
git clone https://github.com/username/username.github.io
<span>cd </span>username.github.io
git pull origin master
</code></pre>
</div>
<p></p>
<h1>JekyllBoostrap</h1>
<p>Github pages also supports <a target="_blank" rel="nofollow" href="https://jekyllrb.com/docs/home/">Jekyll</a>, an easy to use static site generator perfect for blogging. I set up my blog with <a target="_blank" rel="nofollow" href="http://jekyllbootstrap.com/">JekyllBoostrap</a>, a full blog scaffold for Jekyll based blogs. Follow their <a target="_blank" rel="nofollow" href="http://jekyllbootstrap.com/usage/jekyll-quick-start.html">Quick Start Guide</a> for instructions on how to install it.</p>
<p>It also gives detailed instructions on how to set up comments, analytics and permalinks.</p>
<p></p>
<h2>Customizing your page</h2>
<p>Most of the heavy-lifting has already been done for you with JekyllBootstrap but of course there are many options for customizing and adapting your blog’s layout to your liking.</p>
<p>The main file for customizing your page is Jekyll’s “*_config.yml*” file (check back with <a target="_blank" rel="nofollow" href="http://jekyllbootstrap.com/">JekyllBoostrap</a> for details). Here you need to fill it all the relevant information about your page, like title, author, etc.</p>
<p>If you know a little bit about JavaScript, CSS and HTML, you can also directly modify the style sheets in the directory “*_includes*”.</p>
<p>You can change your page’s theme by following <a target="_blank" rel="nofollow" href="https://help.github.com/articles/adding-a-jekyll-theme-to-your-github-pages-site/">this tutorial</a>.</p>
<p>In your page repository’s main folder you have a markdown called “<em>index</em>”. This is your main page and is already set up to show a list of all your blog post.</p>
<p>You can have more pages in the navigation bar if you want, like an “About me”, etc. You simply need to create a new markdown with the respective content in your page repository’s main folder.</p>
<p>You will also automatically get .xml files with your blog’s RSS and Atom feeds.</p>
<p></p>
<h1>Preparing R blog posts with RMarkdown</h1>
<p>I am generally working in RStudio, so this is where I’m preparing all my blog posts. I’m writing my code in RMarkdown and produce html output files until I deem a blog post finished.</p>
<p><a target="_blank" rel="nofollow" href="https://github.com/ShirinG/blog_posts_prep/blob/master/character_network/gilmore_girls.Rmd">This is how an example Rmarkdown document could look like</a>.</p>
<p>Your Rmarkdown will need a header with title, author, date and output information:</p>
<div>
<pre><code><span>---</span><span>
</span><span>title</span><span>:</span><span> </span><span>&quot;This is a test post for my R blog&quot;</span><span>
</span><span>author</span><span>:</span><span> </span><span>&quot;Dr. Shirin Glander&quot;</span><span>
</span><span>date</span><span>:</span><span> </span><span>'`r Sys.Date()`'</span><span>
</span><span>output</span><span>:</span><span> </span><span>html_document</span><span>
</span><span>---</span><span>
</span></code></pre>
</div>
<p>Below the header you can <a target="_blank" rel="nofollow" href="https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf">write text, insert pictures, create tables and much more</a>. Code chunks will go in between brackets.</p>
<div>
<pre><code>```{r, echo=TRUE}
summary(cars)
```
</code></pre>
</div>
<p>As always, there is much more information on <a target="_blank" rel="nofollow" href="http://rmarkdown.rstudio.com/lesson-1.html">how to work with RMarkdown</a> on the webs.</p>
<p>The final code chunk will look something like <a target="_blank" rel="nofollow" href="https://blog.rstudio.org/2016/11/14/ggplot2-2-2-0/">this</a> in the output:</p>
<div>
<pre><code><span>library</span><span>(</span><span>ggplot2</span><span>)</span><span>
</span><span>ggplot</span><span>(</span><span>mpg</span><span>,</span><span> </span><span>aes</span><span>(</span><span>displ</span><span>,</span><span> </span><span>hwy</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>aes</span><span>(</span><span>color</span><span> </span><span>=</span><span> </span><span>class</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_smooth</span><span>(</span><span>se</span><span> </span><span>=</span><span> </span><span>FALSE</span><span>,</span><span> </span><span>method</span><span> </span><span>=</span><span> </span><span>&quot;loess&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>
</span><span>title</span><span> </span><span>=</span><span> </span><span>&quot;Fuel efficiency generally decreases with engine size&quot;</span><span>,</span><span>
</span><span>subtitle</span><span> </span><span>=</span><span> </span><span>&quot;Two seaters (sports cars) are an exception because of their light weight&quot;</span><span>,</span><span>
</span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Data from fueleconomy.gov&quot;</span><span>
</span><span>)</span><span>
</span></code></pre>
</div>
<p><img src="https://i2.wp.com/shiring.github.io/blogging/2016/12/04/diy_your_own_blog_files/figure-markdown_github/unnamed-chunk-4-1.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p></p>
<p>Once I’m happy with my finished blog post, I’m changing the output format in the YAML header to create a markdown file (I’m using markdown_github) and knit again.</p>
<div>
<pre><code><span>output</span><span>:</span><span> </span><span>md_document</span><span>:</span><span>
</span><span>variant</span><span>:</span><span> </span><span>markdown_github</span><span>
</span></code></pre>
</div>
<p>This will produce a markdown document (ending in .md) of your blog post. This markdown is now almost ready to be published but first you need to add a header in the markdown document to the top of your finished markdown for Jekyll to recognize. An example markdown header looks like this:</p>
<div>
<pre><code><span>---</span><span>
</span><span>layout</span><span>:</span><span> </span><span>post</span><span>
</span><span>title</span><span>:</span><span> </span><span>&quot;This is a test post for my R blog&quot;</span><span>
</span><span>date</span><span>:</span><span> </span><span>2016-12-01</span><span>
</span><span>categories</span><span>:</span><span> </span><span>rblogging</span><span>
</span><span>tags</span><span>:</span><span> </span><span>test</span><span> </span><span>ggplot2</span><span>
</span><span>---</span><span>
</span></code></pre>
</div>
<p>It needs to contain the layout definition for post, the title and date. Categories and tags are optional but I like using them to categorize the posts I have written and make them easier to find again.</p>
<p>Now this file is ready to go on your blog.</p>
<p></p>
<h1>Publishing a blog post</h1>
<p>I’m working in a different directory to produce my posts and test out things (in this example called “<em>blog_prep</em>”), so once I have my markdown file ready (in this example called “<em>example_post.md</em>”), I am going back to the terminal window and copy it to my blog repository’s folder “<em>_post</em>” and rename it so that it has the following format: Date-name.md (of course, you could also manually copy, paste and rename the file).</p>
<div>
<pre><code>cp ../blog_prep/example_post.md _posts
mv _posts/example_post.md _posts/2016-11-20-example_post.md
</code></pre>
</div>
<p>If you also have figures or graphs in your blog post, there will be a folder generated along with your markdown with the name “<em>example_post_files</em>”. You need to copy this folder to your blog repository as well. If you gave your post a category, it will look for the files in a folder with the same name as your category with subfolders for the date. With the example above, which was categorized as “<em>rblogging</em>”, I will need to have/ make a folder with the same name and create subdirectories for the date on which my post is published:</p>
<div>
<pre><code>mkdir -p rblogging/2016/12/01
cp ../blog_prep/example_post_files rblogging/2016/12/01
</code></pre>
</div>
<p></p>
<h2>Testing your blog page locally</h2>
<p>Before I push my updated blog to Github where it will go live, I’m testing the output locally with Jekyll. In order to be able to run Jekyll locally, you need to follow <a target="_blank" rel="nofollow" href="http://jekyllrb.com/docs/installation/">these excellent guidelines</a>. Once you have Jekyll up and running, all you need to do is to be in your page repository and run jekyll serve.</p>
<div>
<pre><code>bundle <span>exec </span>jekyll serve
</code></pre>
</div>
<p>This will build your page from the contents of your repository and you can preview whether everything looks the way you want it to.</p>
<p></p>
<p>If my new blog post looks okay and I don’t want to change anything any more, I can finally stage, commit and push the updated blog to Github.</p>
<div>
<pre><code>git add <span>*</span>
git commit -m <span>&quot;name&quot;</span>
git push origin master
</code></pre>
</div>
<p></p>
<p>Alternatively, if you’d rather use RStudio for pushing changes to Github, you can also <a target="_blank" rel="nofollow" href="https://www.r-bloggers.com/rstudio-and-github/">connect your blog repository to RStudio</a> and stage, commit and push from there.</p>
<p></p>
<p>And voilà, your new R blog post is out there for the world to see!</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://shiring.github.io/blogging/2016/12/04/diy_your_own_blog"> Shirin's playgRound</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/rN0q0AJTMe0"></a></div>