knitr::opts_chunk$set( collapse = TRUE, eval = FALSE, comment = "#>" )
library(docmaker)
For this, I followed the instructions over here. I got already python on my machine and I'm a Linux user, so I'm using Ubuntu 20.04
Given that I had already python I just installed MkDocs:
pip install mkdocs
Then I validated that the installation was succesful:
$ mkdocs --version mkdocs, version 1.2.2 from /home/your_username/.local/lib/python3.8/site-packages/mkdocs (Python 3.8)
Done! I got MkDocs on my computer.
I don't like the default theme that comes with MkDocs, so I changed to Matherial.
To install this theme, you will need to run in the terminal:
$ pip3 install mkdocs-material
Now we are all set. We can start creating our Rmarkdown documents:
Create as many Rmd
documents as you need. Each document will be a "section"
on your final website.
Each of the titles and subtitles in your document will be sections inside the specific page.
Also, use relative paths. This will make everything less error prone.
Now, because we are going to use the package docmaker we need to follow a structure:
Rmd
files should be in the root of your project.docs
folder. This is a special folder designated to save the
files needed to build the web page. docmaker
package will be in charge of
the use of this folder, so you don't have to worry about it.docmaker
So far, we have our notes. But we are still lacking the part of publishing in our web page the notes. There are several steps to do this manually but after many times repeating everything I decided to create a small R package to automatize this steps. This package is called dockmaer
You can install the package with:
devtools::install_github("ronnyhdez/docmaker")
Now, on your console you can load the package:
library(docmaker)
docmaker
Before building and deploying our notes, we need to do some configuration steps
in our repository. docmaker
can take care of this with the function:
build_repo(github_page_url = "https://ronnyhdez.github.io/test_docmaker/", site_author = "Ronny A. Hernández Mora")
We can get the URL of our repository in the settings > page on GitHub. After we enabled this in a step before, there should appear the URL designated by GitHub for our web site.
The site_author
should be our name.
This function will do the following:
yml
file.gitignore
the site
folderdocs
folderBecause this is our first time, all of our notes (three in the example) are not
existing as md
documents nor even built or deploy with mkdocs.
docmaker
have a function to take all the .Rmd files existing in our project
root and do all the steps needed to deploy this ones:
make_all_docs(deploy = TRUE)
This function will do the following:
Rmd
files to md
docs
folderREADME.Rmd
file this will be ignoredeploy
is set to TRUE
it will deploy the notes.gh-deploy
Now, given that we are using a new branch to be deployed, we need to go back to
GitHub pages and make a small change: change the branch selected to be build
from main
to gh-pages
After some seconds (or a few minutes), we should be able to see our site alive!
I have created a blog post with more detailed steps if you get confused with the steps setting on your GitHub pages in here
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.