How to Autopost an Rmarkdown File to Blogger
The Rtisan
Thursday, April 2, 2015
The Challenge
I’d like to create a blog that I can automatically post an Rmarkdown file daily.
Step 1
My first solution was to use the RWordPress package in R, but it was not available for my version. My next solution was to automatically post to a blog with an email, which is allowed by Blogger.com (and I’m assuming other blog sites). My first step was therefore to set up a blog with blogger.com.
Step 2
After setting up a blogger account and creating a blog, I needed to set up a blog email address to receive my Rmarkdown files. I used this Google Support site to walk me through the process.
Step 3
Now that I’ve created my blog and my blog email address, I need to set up an R script to knit the Rmarkdown file to html then mail the file to my blog email address. In mailR, keep in mind that html = TRUE and you can post pictures using attach.files.
## library(mailR)
## library(knitr)
## knit2html("blogPosts.Rmd", options = "")
## subject_line <- "How to Autopost an Rmarkdown File to Blogger"
## send.mail(from = "myEmail@work.com",
## to = "mySecrectEmail@blogger.com",
## subject = subject_line,
## body = "blogPosts.html",
## html = TRUE,
## smtp = list(host.name = "smtp.gmail.com", port = 465,
## user.name = "myEmail@work.com",
## passwd = "*******", ssl = TRUE),
## attach.files = blogPostPicture.png,
## authenticate = TRUE, send = TRUE)
Next we save the above script as post2Blog.R and schedule the script to run daily in Windows Task Scheduler.
- Open Task Scheduler and Create a new task
- Under Action tab: use path to Rscript.exe in Program/Script field
- Use post2Blog.R in the Add Attributes field
- Use path to post2Blog.R in the Start in field
No comments:
Post a Comment