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.
Often when writing a new package I find myself simply lifting scripts like
compat-purrr.Rfrom 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 acompat-pkg.Rinto the user'sRdirectory, e.g. from the github for an existing package such as {rlang} where the 'master' version is defined, or from a dedicated repo for tidyversecompat-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}.use_compat()after the 'master' version has changed could update the existingcompat-script after prompting the user to confirm any (potentially breaking) changes.use_compat()could also support single functions, e.g. in the case ofwithr::defer(), which has its owncompat-defer.Rfile in the {rlang} source code.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.Rbegins with the following line:So, perhaps the work is already largely done and the creation of
use_compat()would mainly be a case of compiling allcompat-files which already exist.