Testpage from R resp. knitr

This is the follow-up article from the previous post Publishing R Statistics directly into WordPress. This time I will explain in more detail how to apply the different packages. There is a companion webpage where you can see the content of the different program chunks. You will see how to post text, graphic, uploading files, setting categories and tags, fill in the excerpt and providing a thumbnail.

In contrast to the previous post I have now establised the facility to upload graphics resulted from R calculation automatically to the imgur.com website. This is very important because otherwise the transfer to WordPress would encrypt the pictures to an awful peace of code. An example how this looks can be seen from my first trial.

Introduction

Many of the features in the package are only rudimentary described and implemented. One has to read in detail the description at RWordPress-package. There are listed all the relevant functions with their links to the different WordPress APIs. But most of these links our outdated, because of newer WordPress versions. Now the XML-RPC API is the only relevant code; it supersedes the legacy Blogger, MovableType, and metaWeblog APIs.

A look into the RWordPress-pages in GitHub could also be relevant. See also the XMLRPC package of the same author (Duncan Temple Lang) which is necessary for programming and understanding the functionality of the RWordPress package.

Description

  1. Hello World! — This is my first paragraph, creating a new post with the R chunk upload-article. This chunk is generating the variable postID which I can use for working and elaborating on the same post.
  2. Another line of comment. — I have added this paragraph later on using the R chunk edit-article.
  3. With my next revision of the post I am going to add a code snippet and its output. I am again using the R chunk edit-article. As the output is a graphic I have to declare how to upload the picture. This is done in the R chunk setup-conncection-to-wordpress.

Establishing an upload facility of images is very important because otherwise the transfer to WordPress would encrypt the pictures to an awful peace of code. An example how this looks can be seen from my first trial.

Generated encrypted code when transferring images directly from R to WordPress.

Example of a chunk evaluation with graphic outcome

par(mar = c(3, 2, 0.1, 0.1[/efn_note]
matplot(t(scale(mtcars[/efn_note], lty = 1, type = "l", xaxt = "n", ylab = "")
axis(1, seq(ncol(mtcars[/efn_note], colnames(mtcars[/efn_note]

plot of chunk chunk-evaluation-with-graphic-outcome

Other features

Posting with the RMarkdown Language to WordPress are many hidden features like

  • different types of header
  • different styles of charakters (like italic or bold)
  • active links
  • tables and gprahics

Using RWordPress I have not only transfered text and graphics, but also set different options and some other action in WordPress from the RMarkdown file:

  • Post title
  • Categories
  • Tags
  • Excerpt
  • Thumbnail
  • File upload

But there is much more as one can use all the different WordPress methods. Here is a complete list of supported methods of my weblog. (The ngg.XXX methods refer to the NextGen-Gallery Plugin).

df_methods
##                           myMethods
## 1                  wp.getUsersBlogs
## 2                        wp.newPost
## 3                       wp.editPost
## 4                     wp.deletePost
## 5                        wp.getPost
## 6                       wp.getPosts
## 7                        wp.newTerm
## 8                       wp.editTerm
## 9                     wp.deleteTerm
## 10                       wp.getTerm
## 11                      wp.getTerms
## 12                   wp.getTaxonomy
## 13                 wp.getTaxonomies
## 14                       wp.getUser
## 15                      wp.getUsers
## 16                    wp.getProfile
## 17                   wp.editProfile
## 18                       wp.getPage
## 19                      wp.getPages
## 20                       wp.newPage
## 21                    wp.deletePage
## 22                      wp.editPage
## 23                   wp.getPageList
## 24                    wp.getAuthors
## 25                 wp.getCategories
## 26                       wp.getTags
## 27                   wp.newCategory
## 28                wp.deleteCategory
## 29             wp.suggestCategories
## 30                    wp.uploadFile
## 31                    wp.deleteFile
## 32               wp.getCommentCount
## 33             wp.getPostStatusList
## 34             wp.getPageStatusList
## 35              wp.getPageTemplates
## 36                    wp.getOptions
## 37                    wp.setOptions
## 38                    wp.getComment
## 39                   wp.getComments
## 40                 wp.deleteComment
## 41                   wp.editComment
## 42                    wp.newComment
## 43          wp.getCommentStatusList
## 44                  wp.getMediaItem
## 45               wp.getMediaLibrary
## 46                wp.getPostFormats
## 47                   wp.getPostType
## 48                  wp.getPostTypes
## 49                  wp.getRevisions
## 50               wp.restoreRevision
## 51            blogger.getUsersBlogs
## 52              blogger.getUserInfo
## 53                  blogger.getPost
## 54           blogger.getRecentPosts
## 55                  blogger.newPost
## 56                 blogger.editPost
## 57               blogger.deletePost
## 58               metaWeblog.newPost
## 59              metaWeblog.editPost
## 60               metaWeblog.getPost
## 61        metaWeblog.getRecentPosts
## 62         metaWeblog.getCategories
## 63        metaWeblog.newMediaObject
## 64            metaWeblog.deletePost
## 65         metaWeblog.getUsersBlogs
## 66               mt.getCategoryList
## 67           mt.getRecentPostTitles
## 68             mt.getPostCategories
## 69             mt.setPostCategories
## 70              mt.supportedMethods
## 71          mt.supportedTextFilters
## 72             mt.getTrackbackPings
## 73                   mt.publishPost
## 74                    pingback.ping
## 75 pingback.extensions.getPingbacks
## 76                    demo.sayHello
## 77               demo.addTwoNumbers
## 78                    ngg.installed
## 79             ngg.setPostThumbnail
## 80                     ngg.getImage
## 81                    ngg.getImages
## 82                  ngg.uploadImage
## 83                    ngg.editImage
## 84                  ngg.deleteImage
## 85                   ngg.getGallery
## 86                 ngg.getGalleries
## 87                   ngg.newGallery
## 88                  ngg.editGallery
## 89                ngg.deleteGallery
## 90                     ngg.getAlbum
## 91                    ngg.getAlbums
## 92                     ngg.newAlbum
## 93                    ngg.editAlbum
## 94                  ngg.deleteAlbum

The API can also be used to organise WordPress functionality. So is for instance possible to inspect and manipulate tags in a much more convenient way as this is possible under WordPress it self. The above tables gives you a first impression of summary displays.

At the moment (August 2017) I have not understood completely how to write function using the new API. I am lacking knowledge in R programming but I need also to learn more about the structure and components of the XML-RPC protocol. So most of the time I have either used or slightly adapted functions from the RWordPress-package.

Conclusion

This post war completly written in RMarkdown with the R environment RStudio an open source professional software for R. R Markdown documents are fully reproducible. I used the productive notebook interface to weave together narrative text and code to produce elegantly formatted output. The origin file is just text and can be read and/or manipulated easily with many other programmes. As everything is just marked text and based on open source there is no dependency from propiretary programs. Therefore reproducibility of the results but also the sustainability of the pure text publication is high.

Following this trend one should (in the future) — instead of the very complex machinere of WordPress — use web publishing systems that are open source and purely text based like for instance Jekyll. And in that case one can use for complete books collabortive versioning systems Git and GitHub.

Additional Material

RPubs: You can also inspects both articles how the look at RPubs, a free service by RStudion.

GitHub You can also inspect the source code and comment or push changes, improvements etc.

Von Peter Baumgartner

Seit mehr als 30 Jahren treiben mich die Themen eLearning/Blended Learning und (Hochschul)-Didaktik um. Als Universitätsprofessor hat sich dieses Interesse in 13 Bücher, knapp über 200 Artikel und 20 betreuten Dissertationen niedergeschlagen. Jetzt in der Pension beschäftige ich mich zunehmend auch mit Open Science und Data Science Education.

Schreiben Sie einen Kommentar

Ihre E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert