Create blog posts from RStudio to WordPress

421 篇文章 14 订阅

In a couple of courses I’ve used RPubs and GitHub for publishing my R code and work. As I have a own website withWordPress I want to blog from R to my own blog instead only through sharing R code via RPubs and GitHub. After searching over the internet I find some usefull stuff to do this. So let’s try it myself en let this be my first blog post created from Rstudio to WordPress.

Setting up WordPress and R

What do we need for wordpress:
And in R we need:
  • knitr, a website is coded in HTML, knitr can convert your R code from a R Markdown file to HTML code, this package is already installed with RStudio.
  • RWordPress allows publish blog posts from R to WordPress.
Load the necessary packages in R

Setting options for RWordPess

Syntax highlighting with Crayon Syntax Highlighter

To make syntax highlighting work in WordPress with the Crayon Syntax Highlighter plugin. R code should be enclosed in WordPress-shortcode instead of the knitr html output default

to

We can’t do that with the default knitr2wp function of knitr. knitr2wp is only based on the syntax which is used forSyntaxHighlighter. I don’t want to update all my other code on my blog.

For the Crayon Syntax Highlighter I’ve found a request of allowing proper code highlight when using Crayon. Below the copied requested function for using it to post a blog to my WordPress site with Crayon Syntax Highlighter as code highlighter.

After adding the function into R we can post our first blog on WordPress and that would be this one :).

Publishing the post to your blog

Note: Below code should run directly from the R shell (first create the above function and load the RWordPress library) after the R Markdown has created and has runs once. It will post a lots same drafts and ends with a error. I cannot figure out why, I think there is a loop and it wants to post itself to your blog. If you want to upload it run it directly from the R shell with the upload option to TRUE.

I set the publish option to FALSE, so the post will stay in draft mode and I can fine tune some formats, tags, set a featured image  and add on the top the shortcode for using L^AT_X syntax.

This code can also be find on my GitHub.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值