Packages in non-standard repositories: What to do when submitting your own R package to CRAN

I’m currently finalising the submission of my packages FRK to CRAN. It depends on several packages, but not all of these are available on CRAN. Now, CRAN requires packages that are not available in mainstream repositories to be put into their own repositories, and their URLs then need to be specified in the Additional_respositories in the Description; see the package DESCRIPTION for an example.

If your aspiring CRAN package depends on a home-brewn package that will never make it to CRAN (e.g., a data package), then it needs to be put into its own repository. This seemed duanting to me until I came across this website here which explains how to construct your own repository on github pages. Basically the steps are as follows

  1. Create a new repo on github
  2. Create a repo of the same name using the instructions in the webpage
  3. Push the changes to the gh-pages branch

The last step is important; if these are not put in the gh-pages branch then these will not be visible by R CMD check.

One thing which took some time to figure out (thanks to Clint Shumack for helping me out) was that R CMD check was only checking for repos with http… unfortunately gh-pages enforces https. This, however, was because my R was outdated. As from R 3.3 R CMD check has full support for repositories which have to be accessed using https.

How do you know it is working correctly? When you do an R CMD check on your package you should get something which looks like

Suggests or Enhances not in mainstream repositories:
dggrids
Availability using Additional_repositories specification:
dggrids yes https://andrewzm.github.io/dggrids-repo

Publishing from R straight to wordpress.com

This post has been written in Rstudio using RMarkdown and then uploaded to wordpress.com using the knitr package of Yihui. The way in which this is done is excellently documented here and here. In this post I just wish to outline some minor observations and difficulties I encountered.

Installation

Installation of RWordPress, the required package for posting from R to WordPress, was pretty straightforward after installing the xml2-dev package on Ubuntu 14.04 using sudo apt-get install libxml2-dev:

 install.packages('RWordPress',
                  repos = 'http://www.omegahat.org/R',
                  type = 'source')

On CentOS the required package is libxml2-devel, however I did not manage to get R to post to wordpress.com on this platform (several HTML errors)

Publishing to wordpress.com

There are four steps to publish to wordpress.com.

1. If you have two-stage verification set up then you have to login to wordpress.com and set an Application Password. All this does is generate a code which can be used by R or any other application for that matter, to bypass the two-stage authentication. I suggest you do this everytime you need to do a post and then delete the application password after each post.

2. Set your login options. This is done through

library(RWordPress)
options(WordPressLogin = c(user = 'password'),
        WordPressURL = 'https://user.wordpress.com/xmlrpc.php')

One note about this, the label user is your actually username. So say your username is my_username then the function argument would be c(my_username = 'password'). The password is enclosed within the inverted commas and, if you have two-stage authentication, this would be the application password generated by wordpress.com. The second argument then is https://my_username.wordpress.com/xmlrpc.php. Also please note that https needs to be used and not http.

3. Set the image base directory. Here I will follow Yihui’s recommendation and suggest the use of a Dropbox public folder for this, for example ~/Dropbox/Public/wpintro. The options are then set as follows

library(knitr)
opts_knit$set(base.url = 'https://dl.dropboxusercontent.com/u/3038814/wpintro/',
              base.dir = '~/Dropbox/Public/wpintro/')

where 3038814 is replaced by your own user code. This can be found by simply uploading a file into the public folder, going on the Dropbox website, right clicking on the file and choosing Copy public link….

I show this works in principle by plotting the following figure:

x <- seq(0,100,by=0.1)
y <- sin(2*pi*0.1*x)
plot(x,y)

plot of chunk unnamed-chunk-4

4. I had a small problem with paths which I haven’t resolved yet. In particular, I only manage to get the figures in the right subdirectory if I change the path to ~/Dropbox/Public/wpintro/ and run knitr from this location. This is not much of a problem, so I will keep it at that for now. The final commands you need to run therefore are

setwd('~/Dropbox/Public/wpintro')
knit2wp('/path/to/RMD/file',
        title = 'My Post Title',
        publish = FALSE,
        shortcode = TRUE)

The publish=FALSE flag allows you to first review the post on WordPress.com before publishing it.