tidyverse/design

Working with multiple versions of a package

hadley opened this issue · 2 comments

Sometimes a package that you depend on changes its API in a non-backward compatible way. This article shows you how to make your package work with both versions.

  • What to condition on (removed vs. changed) — best to check for existence of some object, e.g. exists("unnest_legacy", asNamespace("tidyr")). We no longer recommend testing for a specific package version, it's fragile and relatively slow.

  • How to test — what to put in .travis and what to put in your tests

matrix:
  include:
    - r: 3.5
      name: tidyr-devel
      before_script: Rscript -e 'remotes::install_github("tidyverse/tidyr")'

Also: it's nice to specify env to label this build in the matrix.

Sometimes you also want to work the problem the other way 'round, i.e. make sure your package still works with the previous version of a dependency for a while.

Example of both (from readxl's .travis.yml):

matrix:
  include:
    - r: release
      env: tibble='v1.4.2'
      before_script: Rscript -e "remotes::install_version('tibble', '1.4.2')"

Update: Oh I see name in yours now. Maybe that's even nicer than using env?

Yeah, name is a new thing that's nicer than env