Using R Studio cloud for teaching package development

I recently set up an R Studio cloud workspace as a backup for our Forwards package development workshop:
https://rstudio.cloud/spaces/1769/join?access_code=LwZsX1pmxEGrpCRbTqrJrFETSwzLP4zmqdpVYUD%2B
It contains some example packages (mylittlepony and hadcol) and allows collaborators (workshop participants) to create their own package projects (as I have done in mypkg).

I was pleased to see that build tools and git were already set up - perfect! However I found that users could not build a package from a standard set up, i.e. where the package directory = the project directory. This is because they do not have permission to create the tarball outside the project directory.

I tried to solve the problem by putting the package in a subdirectory and configuring the build tools to set that directory as the package directory. This does mean that "Build Source Package" from the build menu works (as well as everything else on the build menu) however most participants preferred to type R commands directly in the console and all the devtools functions then require the subdirectory to be specified, which caused a lot of confusion because that wasn't on the workshop slides. Moreover some usethis functions do not have the option to specify a subdirectory, e.g. use_vignette(), though in that case devtools::use_vignette() can be used instead.

So at the moment there are a couple of options:

  1. Change the workshop slides to use subdirectories all the time or explain when we need to do this - not ideal, as this is not the structure that we recommend in general and it just adds that extra level of complication for an introductory workshop.
  2. Use the standard setup, but if working in RStudio cloud don't build the package. Okay, but then there is still an issue with check: using devtools::check() in the console works, but using check from the build menu doesn't (permissions issue again, not sure why there's a difference here).

I guess 2 is the best solution if we want to use RStudio.cloud to teach package development, as then most things work as standard with just a couple of things where we have to say "this won't work in the cloud".

But maybe RStudio.cloud could be set up somehow to allow the standard workflow? Perhaps create the project directories in a subdirectory, e.g. cloud/user/project, so the user could write files to the level above the project directory? Or somehow make it work so these auxiliary files from build/check get put in a temp directory?

There are a couple outstanding issues related to build menu options. Specifically the Check Package, Build Source Package, and Build Binary Package commands default to the parent directory of the project directory (/cloud) in order to save output - which as you noted is unreadable.

There are two workarounds for how to handle this,

  1. As you noted you can place the projects contents in a subdirectory of the project directory (making /cloud/project/package the package root rather then /cloud/project). The defaults should operate correctly from that point on.

  2. You can also use the associated commands from the command line. This lets you override the location that output is saved when needed,

    devtools::check()
    devtools::build(path='/tmp')
    devtools::build(binary = TRUE, path='/tmp')

2 Likes

Ah thanks - the bit that I was missing was to move the project.Rproj into the subdirectory as well. Then as you say I don't need to configure the build tools at all, just reopen the project and everything works as standard.

Problem solved!

1 Like

I also want to use a standard setup (i.e. the package in the root, not in sub directories). It took a while to devise a procedure that works smoothly, which I've copied below. I wonder if this is more complicated than necessary?

  • Create a new project.
  • Select project.Rproj and rename to your package name, e.g. mypkg.Rproj
  • install.packages("roxygen2")
  • install.packages("devtools")
  • devtools::setup(description = list("Package" = "mypkg")).
  • Select the option that agrees to overwriting.
  • From the Tools menu select Project Options... and then Build Tools.
  • Select Package from the Project build tools drop-down menu.
  • Check Generate documentation with Roxygen and then check all the unchecked options. Click OK.
  • In the Build tab click Install and Restart. (The build should be successful.)
  • Edit and add fields in DESCRIPTION as appropriate.

To build a Source Package do the following:

  • Create a new folder tmp
  • devtools::build(path = "tmp")
  • The resulting file, e.g. mypkg_0.0.0.9000.tar.gz can be downloaded to your computer.