usethis 2.0.0

CRAN release: 2020-12-10

Adoption of gert and changes to Git/GitHub credential handling

Usethis has various functions that help with Git-related tasks, which break down into two categories:

  1. Git tasks, such as clone, push, and pull. These are things you could do with command line Git.
  2. GitHub tasks, such as fork, release, and open an issue or pull request. These are things you could do in the browser or with the GitHub API.

We’ve switched from git2r to the gert package for Git operations (https://docs.ropensci.org/gert/). We continue to use the gh package for GitHub API work (https://gh.r-lib.org).

The big news in this area is that these lower-level dependencies are getting better at finding Git credentials, finding the same credentials as command line Git (and, therefore, the same as RStudio), and finding the same credentials as each other. This allows usethis to shed some of the workarounds we have needed in the past, to serve as a remedial “credential valet”.

Under the hood, both gert and gh are now consulting your local Git credential store, when they need credentials. At the time of writing, they are using two different even-lower-level packages to do this:

Even now, gert and gh should discover the same credentials, at least for github.com. In the future, these two packages may merge into one.

Git/GitHub credential management is covered in a new article: Managing Git(Hub) Credentials

The main user-facing changes in usethis are:

  • usethis should discover and use the same credentials as command line Git.
  • usethis should be able to work with any GitHub deployment. While github.com is the default, GitHub Enterprise deployments are fully supported. The target GitHub host is determined from the current project’s configured GitHub remotes, whenever possible.

As a result, several functions are deprecated and several other functions have some deprecated arguments.

  • Deprecated functions:
    • use_git_credentials()
    • git_credentials()
    • github_token()
  • Functions with (deprecated arguments):

The switch to gert + credentials should eliminate most credential-finding fiascos. Gert also takes a different approach to wrapping libgit2, the underlying C library that does Git operations. The result is more consistent support for SSH and TLS, across all operating systems, without requiring special effort at install time. More users should enjoy Git remote operations that “just work”, for both SSH and HTTPS remotes. There should be fewer “unsupported protocol” errors.

GitHub remote configuration

Usethis gains a more formal framework for characterizing a GitHub remote configuration. We look at:

  • Which GitHub repositories origin and upstream point to
  • Whether you can push to them
  • How they relate to each other, e.g. fork-parent relationship

This is an internal matter, but users will notice that usethis is more clear about which configurations are supported by various functions and which are not. The most common configurations are reviewed in a section of Happy Git.

When working in a fork, there is sometimes a question whether to target the fork or its parent repository. For example, use_github_links() adds GitHub links to the URL and BugReports fields of DESCRIPTION. If someone calls use_github_links() when working in a fork, they probably want those links to refer to the parent or source repo, not to their fork, because the user is probably preparing a pull request. Usethis should now have better default behaviour in these situations and, in some cases, will present an interactive choice.

Default branch

There is increasing interest in making the name of a repo’s default branch configurable. Specifically, main is emerging as a popular alternative to master. Usethis now discovers the current repo’s default branch and uses that everywhere that, previously, we had hard-wired master.

git_branch_default() is a newly exported function that is also what’s used internally.

use_course(), use_zip(), and create_download_url() all have some support for forming the URL to download a .zip archive of a repo, based on a repo specification (e.g. OWNER/REPO) or a browser URL. These helpers now form a URL that targets HEAD of the repo, i.e. the default branch.

Changes to Git/GitHub functionality

The default Git protocol is now “https” and we no longer provide an interactive choice, by default, in interactive sessions. As always, a user can express a preference for “ssh” in individual function calls, for an R session via use_git_protocol(), and for all R sessions via the usethis.protocol option (#1262).

pr_resume() is a new function for resuming work on an existing local PR branch. It can be called argument-less, to select a branch interactively.

pr_fetch() can also be called with no arguments, to select a PR interactively. The owner argument is replaced by target, with a choice of the source (default) or primary repo.

pr_forget() is a new function for abandoning a PR you initiated locally or fetched from GitHub. It only does local clean up and, for example, doesn’t delete a remote branch or close a PR (#1263).

pr_view() can now be called with no arguments. If the current branch is associated with an open PR, we target that and, otherwise, we offer an interactive selection.

pr_finish() deletes the remote PR branch if the PR has been merged and the current user has the power to do so, i.e. an external contributor deleting their own branch or a maintainer deleting a branch associated with an internal PR (#1150). It no longer errors if the PR branch has already been deleted (#1196).

pr_pull_upstream() is renamed to pr_merge_main() to emphasize that it merges the main line of development into the current branch, where the main line of development is taken to mean the default branch, as reported by git_branch_default(), of the source repo, which could be either upstream or origin, depending on the situation.

create_from_github() will only create a read-only clone, due to lack of a GitHub personal access token, if explicitly directed to do so via fork = FALSE.

create_from_github() and use_tidy_thanks() accept browser and Git URLs as the repo_spec argument, to be friendlier to copy/paste. When a URL is passed, the host is also extracted from it.

create_github_token() is a new name for the function previously known as browse_github_token() and browse_github_pat().

issue_close_community() and issue_reprex_needed() are two new functions for maintainers who process lots of GitHub issues. They automate canned replies and actions, e.g. labelling or closing (#940).

GitHub Actions is the preferred platform for continuous integration, because that is what the tidyverse team currently uses and maintains. Functions related to Travis-CI and AppVeyor are soft-deprecated to raise awareness about this change and to make it clear that, if substantial maintenance becomes necessary, we may elect to retire the function (#1169).

browse_github_actions() is a new function to open the Actions page of the respective repo on GitHub, similar to existing browse_*() functions (@pat-s, #1102).

use_github_pages() is a new function to activate or reconfigure the GitHub Pages site associated with a repository (#224).

use_tidy_pkgdown() implements the complete pkgdown configuration used by the tidyverse team (#224).

pr_sync() is deprecated and can be replicated by calling pr_pull(), pr_merge_main(), then pr_push().

Other changes

browse_package() and browse_project() are new functions that let the user choose from a list of URLs derived from local Git remotes and DESCRIPTION (local or possibly on CRAN) (#1113).

The legacy "devtools.desc" option is no longer consulted when populating a new DESCRIPTION file. You must use the "usethis.description" now (#1069).

use_dev_package() gains a remote parameter to allow you to specify the remote. The existing behaviour, which adds an OWNER/REPO GitHub remote, remains the default (#918, @ijlyttle).

use_cpp11() is a new function to set up an R package to use cpp11.

create_package(roxygen = FALSE) once again writes a valid NAMESPACE file (and also has no Roxygen* fields in DESCRIPTION) (#1120).

create_package(), create_project(), create_from_github(), and proj_activate() work better with relative paths, inside and outside of RStudio (#1122, #954).

use_testthat() gains an edition argument to support testthat v3.0.0 (#1185)

use_version() now updates src/version.c if it exists and contains a line matching PKG_version = "x.y.z";.

usethis has been re-licensed as MIT (#1252, #1253).

Dependency changes

New Imports: gert, jsonlite (was already an indirect dependency), lifecycle, rappdirs

No longer in Imports: git2r, rematch2

usethis 1.0.0

CRAN release: 2017-10-22

This is a new package that extracts out many functions that previously lived in devtools, as well as providing more building blocks so you can create your own helpers. As well as the many new helpers listed below, there are three main improvements to the package:

  • More support for general R projects, other than packages.
  • A notion of an “active” project that all commands operate on.
  • Refined output.

usethis is gradually evolving towards supporting more general R “projects”, not just packages. This is still a work in progress, so please let me know if you use a function that you think should work with projects but doesn’t. You can also try out the new create_project() which creates a basic RStudio project.

The concept of the working directory and the “base path” have been refined. Rather than using an argument to specify the active project, all use_ functions now use a global active project setting, as returned by proj_get(). This is cached throughout a session, although it will be updated by create_package() and create_project(). You’ll now get an clear error if you attempt to use_something() outside of a project, and create_something() will warn if you’re trying to create inside an existing project.

The output from all usethis commands has been reviewed to be informative but not overwhelming. usethis takes advantage of colour (using crayon and RStudio 1.1) to help chunk the output and clearly differentiate what you need to do vs. what has been done for you.

New functions

  • use_apl2_license() if you want to use the Apache 2.0 license.

  • use_depsy_badge() allows including a Depsy badge (@gvegayon, #68).

  • use_dev_package() works like use_package() but also adds the repo to the Remotes field (#32).

  • use_github_labels() will automatically set up a standard set of labels, optionally removing the default labels (#1).

  • use_pipe() creates a template to use magrittr’s %>% in your package (#15).

  • use_tidy_ci() which sets up travis and codecov using the tidyverse conventions (#14)

  • use_tidy_description() puts description fields in a standard order and alphabetises dependencies.

  • use_tidy_eval() imports and re-exports the recommend set of tidy eval helpers if your package uses tidy eval (#46).

  • use_usethis() opens your .Rprofile and gives you the code to copy and paste in.

New edit functions

A new class of functions make it easy to edit common config files:

  • edit_r_profile_user() opens .Rprofile
  • edit_r_environ_user() opens .Renviron
  • edit_r_makevars_user() opens .R/Makevars
  • edit_git_config_user() opens .gitconfig
  • edit_git_ignore_user() opens .gitignore
  • edit_rstudio_snippets(type) opens ~/R/snippets/{type}.snippets

Updates

  • use_coverage("codecov") now sets a default threshold of 1% to try and reduce false positives (#8).

  • use_description() now sets ByteCompile: true so you can benefit from the byte compiler (#29)

  • The license functions (use_mit_license(), use_apl2_license(), and use_gpl3_license()) save a copy of the standard license text in LICENSE.md, which is then added to .Rbuildignore. This allows you to follow standard licensing best practices while adhering to CRANs requirements (#10).

  • use_package_doc() uses more a modern roxygen2 template that requires less duplication.

  • use_test() will use the name of the currently open file in RStudio if you don’t supply an explicit name (#89).

  • use_readme_rmd() now puts images in man/figures/ and no longer adds to .Rbuildgnore. This ensures that the rendered README.md will also work on CRAN (#16, #19). The first chunk now uses include = FALSE and is named setup (#19).

  • use_revdep() creates structure for use with revdepcheck package, the preferred way to run revdepchecks. (#33)

Bug fixes and minor improvements

  • Functions which require code to be copied now automatically put the code on the clipboard if it is available (#52).

  • create_package() no longer creates a dependency on the current version of

  • use_build_ignore() now strips trailing /

  • use_git() will restart RStudio if needed (and possible) (#42).

  • use_github() now has an organisation parameter so you can create repos in organisations (#4).

  • use_template() and use_test() now convert title to a slug that only contains lowercase letters, numbers, and -.

  • use_vignette() now adds *.html and *.R to your .gitgnore so you don’t accidentally add in compiled vignette products (#35).

  • use_travis_badge() and use_appveyor_badge() are now exported functions, so they can be used even if ci was separately set up (#765, @smwindecker).