Usually I work in RStudio to write my homeworks, to create presentations and of course to do statistical analysis. When I moved my blog to Github pages and started using Jekyll, I started looking for solutions to use RMarkdown also. There are some sources online showing how this can be done, like this, this, or this but I wanted some easy solutions to automate the workflow.
First we need to convert the .Rmd file we write in RStudio to a vanilla .md file in order Jekyll to handle it. Derek Feng has a great
make.R file on this Github page. I used this file and changed it to accept the file name argument from the zsh script result. I put this R file into the main directory of the blog. Also I created an _Rmd folder to save the Rmarkdown files.
For Alfred, I wrote 2 workflows (using Matthew Guay’s great workflow Publish to Kirby from Alfred as my template). First one of these workflows creates an Rmd file with the date in the name along with the query typed in Alfred. The second workflow finds the newest file in the Rmd directory and converts it to a vanilla md file and saves it in posts/articles directory.
First workflow has 3 options in it, articles, blog, and page. These were the default layouts with So Simple Theme so I sticked with them. If you create blog or page, Alfred opens Mou for editing. I opted for Mou because it has a built in viewer. Of course, this behavior can be easily changed. Here are the Alfred scripts.
This one creates an
This one creates a blog post.
And this one creates a page.
The second workflow is specific to Rmd file as I mentioned above. This is how the workflow looks like.
I used the following script to convert Rmd to md using make.R file.
since this is written in RMarkdown let’s test it also with a small part of default Rmarkdown file.
You can embed an R code chunk like this:
You can also embed plots, for example:
Note that the
echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.
It seems that RMarkdown works properly. The only problem I experienced is that the Plain Code Blocks do not work. Instead of Plain Code Blocks I used R code block with
eval=FALSE. You can access my version of
make.R here. You can access Alfred workflows here.