Skip to content

Provide use_compat() for managing common compat-[pkg].R files #1654

Description

@wurli

Often when writing a new package I find myself simply lifting scripts like compat-purrr.R from the {rlang} source-code to avoid taking on more dependencies than necessary. I think formalising this process would be well worth the effort. E.g. it could be done as follows:

  • use_compat(pkg) would copy a compat-pkg.R into the user's R directory, e.g. from the github for an existing package such as {rlang} where the 'master' version is defined, or from a dedicated repo for tidyverse compat- files. The second option seems better to me as it would also provide a nice place to look for such files without necessarily having to go through {usethis}.
  • Re-running use_compat() after the 'master' version has changed could update the existing compat- script after prompting the user to confirm any (potentially breaking) changes.
  • use_compat() could also support single functions, e.g. in the case of withr::defer(), which has its own compat-defer.R file in the {rlang} source code.
  • Specifically, I think standardising 'compat' files for at least the following packages would be really useful: {cli}, {dplyr}, {forcats}, {glue}, {purrr}, {rlang}, {stringr}, {vctrs}, {withr} and {zeallot}

Obviously the real value here would be in having such compat- scripts readily available. However it sees like this is already somewhat of a 'soft-supported' service from the Tidyverse, to wit, rlang/compat-vctrs.R begins with the following line:

# Latest version: https://github.com/r-lib/rlang/blob/main/R/compat-vctrs.R

So, perhaps the work is already largely done and the creation of use_compat() would mainly be a case of compiling all compat- files which already exist.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementtidy ✨tools for the tidyverse team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions