기타활동/기타

Uploading R markdown documents to Wordpress

늘근이 2018. 5. 22. 12:50

Get your packages below


 install.packages("devtools")

 install.packages("RCurl")

 install.packages("XML")

 devtools:::install_github("duncantl/XMLRPC")

 devtools:::install_github("duncantl/RWordPress")


 library(XML)

 library(XMLRPC)

 library(RWordPress)

 library(knitr)


Wordpress has convinient feature called XMLRPC. This will directly upload the R markdown Rmd file to your Wordpress.

Package knitr is for converting Rmd to executed R results, RWordPress is for uploading the contents.


1) Now, set working directory to the directory which contain files you want to upload.

2) Set options, provide username and password. Remember! no quotes for username, and yes quotes for password.

3) Call knit2wp


setwd("C://Dropbox//Paper//material")


options(WordpressLogin = c(xxxxusername = 'xxxxpassword'), 

        WordpressURL = 'http://yourwpaddress.com/xmlrpc.php') 


knit2wp('yourRmd.Rmd', title = 'This will be your title', publish = FALSE) 

 



Troubleshoot ---

Error in getOption("WordpressLogin", stop("need a login and password")) : 

  need a login and password

In the options() method, you have to carefully look at the capital letter 'P'. older version uses WordPressLogin, while recent version uses WordpressLogin. 

(Just telling that I spent my precious Saturday 1 hour to find out this minor thing)



Warning message:

In native_encode(readLines(con, warn = FALSE)) :

  some characters may not work under the current locale

This will happen if you are using language other than English in Window machine. 

Using mac solved the problem.. This has to be related to Window locale system.



Warning message:

In writeLines(if (encoding == "") res else native_encode(res, to = encoding),  :

  invalid char string in output conversion





'기타활동 > 기타' 카테고리의 다른 글

sudo crontab -e 0 4 * * * /sbin/shutdown -r now  (0) 2018.12.13
find all directories on min / max depth  (0) 2018.05.02
태블릿  (0) 2018.03.17
통계학과 커리큘럼 참조  (0) 2018.01.26
공공데이터 링크  (0) 2017.08.16