At the end of discussion on how to produce HTML
documents from .Rmd
the official page of the rmarkdown
package mentions that entire website can be produced using R Markdown and the described methodology.
Creating a website similar to rmarkdown.rstudio.com can be accomplished using a combination of GitHub Pages and Jekyll (static website generator). The current guide narrates the process of publishing a statitic, blog-aware website from a GitHub repository containing multiple .html files, printed from .Rmd files and united by common attributes in the **_output.yaml**
options file.
To organize the process of learning new concepts and terminology we start with GitHub Pages Help. There is a difference between producing a website for a user or organization, and the a website for a specific project. One can use an Automatic Page Generator, but from my understanding so far the limitations of this approach might be substantial. Please report on the use of this technique in the comments and I’ll update this section.
To set up Jekyll publishing you will need (I)Ruby language, (II)dependency manager Bundler and (III)atomatic page generator Jekyll :
DevKit
inside the folder where Ruby was installed.Open the folder wher DevKit was unzipped
cd c:\Ruby193\DevKit
Generate config.yml
file:
ruby dk.rb init
and edit it (optional) to add or remove Rubies.
Finally, enhance your Rubies with DevKit:
ruby dk.rb install
Test installation:
gem install json --platform=ruby
you should see “with native extensions”" in the screen messages. To confirm that the json gem is working, run:
ruby -rubygems -e "require 'json'; puts JSON.load('[42]').inspect"
This is supposed to return “42” for a successful test. For more see [Jekyll installation guide for Windows] (http://jekyll-windows.juthilo.com/)
Now you need to install Bundler into the root directory of your GitHub repository (Important: make sure that you’ve selected gh-pages branch). a. Open the local folder of you repositoyr (~GitHub/RepositoryName) b. Initiate command prompt by typing cmd
in the address bar of the File Explorer
c. Type in gem install bundler
in the command line
- the text should say that the 1 gem has been installed
Gemfile.txt
in the root of the repositoryThe content of the file is
source 'https://rubygems.org'
gem 'github-pages'
Gemfile.txt
into Gemfile
Run command line bundle install
The code in step (d.) should executed for each repository you want to publish as a website, whereas the installation of Bundler (step II.) is done once per machine.
Jekyll will take the collection of files and folders in the “gh-pages” of your repository and assemble a static website out of them.
Here I demonstrate how to replicate verbatim the styles and settings from the official website of rmarkdown.
Go to the gh-pages branch of the rmarkdown GitHub repository (you may need to clone it to your machine if you haven’t done so already)
Makefile
- clarify the function_output.yaml
- defining the common output options for .Rmd filesNOTE: I’m still working on editing the styles of the site. Two routes are possibles:
- Route One : edit the min.js style libraries directly - Route Two : find a better fitting Bootstrap templates.
These routes need researching before recommendation for reproduction. Please report your tests in the comments.
At this point the website is a collection of .Rmd files stored in a single repository. Their output attributes are shared and controlled by output.yaml
in the root. To produce the website execute the following steps:
path_index<- base::file.path("./index.Rmd")
path_ghPages<- base::file.path("./gh-pages-setup.Rmd")
path_workStation<- base::file.path("./work-station-setup.Rmd")
buildthese<- c(path_index, path_ghPages,path_workStation)
for( pathRmd in buildthese ) {
rmarkdown::render(input = pathRmd,output_format=c("html_document"), clean=TRUE)
}
Open command line from the repository’s root and execute
bundle exec jekyll serve
This will assemble the website and deploy it to the local host. Examine it at
localhost:4000
Alternatively, you can add this line at the end of “produceReports.R” script
# base::system("bundle exec jekyll build")
# or
# base::system("bundle exec jekyll serve")
However, I’m not sure, whether the working directory is passed to jekyll or not. Needs testing.
Commit and sync the changes in the gh-pages branch. The website should become availible at
username.github.io/projectname
or a custom address.
To change the website one must repeat these steps after introducing changes in the initial .Rmd files
Register an account with Disqus if you haven’t already.
When logged in go to Settings got Admin area
Click on the drop-down button and select “Add new site”
Enter the names of your blog, that will be hosted on disqus servers.