Procedure to create a project for a package destined for GitHub?

What is the canonical procedure for starting a new package that you want to put on GitHub (etc)?

When I start a New Project, I have the option to either check out a directory from version control or to create a package. Currently, my procedure is to create a new repository on GitHub, then start a new project by checking out that repository, then doing a dance using devtools::create()/ package.skeleton etc, deleting files, and restarting RStudio, until the version control is synced and RStudio recognizes that this is a package project. Or I clone the repository outside of RStudio and then start the project in that directory.

This dance only happens when I want to start a package, so the overhead is no big deal. (Though in a class it's noticeable.) But I wonder if there's a better way to combine these apparently mutually exclusive ways to start a project. I understand it would be a pain to develop an option to create a new repository, clone it, and start a new package all in one step, because starting a package afresh allows you to safely make a lot of assumptions about the directory contents.

2 Likes

You could avoid going through the GitHub web UI by creating the new repo from the Terminal.

A couple possible scripts:

I go through the same song and dance too. Create on github, create project in RStudio, etc. But I do know that usethis::use_github() is a thing. I have never tried it though.

Update: I'm about to post an updated response, incorporating some feedback and in light of usethis changes made as a result of this productive discussion!

I think this is easiest:

  • Create repo on GitHub (YES to Initialize this repository with a README)
  • Capture URL from the big green "Clone or download" button
  • Make a new RStudio Project with this URL
  • usethis::create_package(getwd()) (hmm ... maybe that should be less awkward?). Note: usethis is not on CRAN yet.

Sticking to CRAN packages does involve a bit more friction.

The "GitHub first" approach:

  • Create repo on GitHub (YES to Initialize this repository with a README)
  • Capture URL from the big green "Clone or download" button; new RStudio Project from that
  • devtools::setup()
  • Quit and Relaunch RStudio in this Project.

The "GitHub last" approach:

  • From a running RStudio instance: devtools::create("path/to/your/new/pkg").
  • Also from the existing RStudio instance: browseURL("path/to/your/new/pkg.Rproj") to launch a new instance of RStudio in the new pkg/Project.
  • In the new pkg/Project, devtools::use_github().
8 Likes

Take 2 on my "easiest" response. I got some feedback from @jimhester and @hadley also smoothed a rough edge in usethis.

Easiest, if you're willing to use dev usethis, which is not on CRAN yet:

  • usethis::create_package("path/to/your/new/pkg"). This will launch into a new instance of RStudio in the new pkg/Project.
  • usethis::use_git()
  • usethis::use_github()
5 Likes

I use hub and command line. It looks like usethis is going to be very similar in functionality to hub

I like using Gabor's https://github.com/metacran/mason, which sets up the package as well as the git and github repositories.

1 Like

Good call, Noam! @hughparsonage, the mason template for a "minimal R package" is here (you'll of course also need mason, which @noamross linked to above)!