Undo `usethis::use_XYZ()`

366 Views Asked by At

I'm developing a package in RStudio with usethis, trying to make use of best practices. Previously, I had run usethis::use_tidy_eval(). Now, I'm using data.table, and set this up by running usethis::use_data_table(). I get a warning,

Warning message:
replacing previous import ‘data.table:::=’ by ‘rlang:::=’ when loading ‘breakdown’ 

because the NAMESPACE contains the the two lines:

importFrom(rlang,":=")
importFrom(data.table,":=")

It turns out I no longer need usethis::use_tidy_eval(), so I'd like to revert it and in doing so get rid of the warning.

How can I undo whatever usethis helper functions do? Must I edit the NAMESPACE myself? How do I know what else was modified by usethis::use_tidy_eval()? What about undoing usethis::use_pipe()?

2

There are 2 best solutions below

2
Calum You On

Unless you made a Git commit before and after running that code, there's probably not an extremely easy way. The two options I'd consider would be:

Read the source code of the function. This can require some hopping around to find definitions of helper functions, but use_tidy_eval looks like it:

  1. adds roxygen to Suggests in DESCRIPTION
  2. adds rlang to Imports in DESCRIPTION
  3. adds the template R file tidy-eval.R
  4. asks you to run document() which is what actually updates the NAMESPACE. You can find the lines added by looking for the importFrom roxygen tags in the template file.

To undo this, you should just be able to delete all of the above. However, you need to be a bit careful - e.g. if you import functions from rlang outside of tidy-eval.R, removing it from DESCRIPTION might prevent installation. Hopefully any such issues would be revealed by devtools::check() if they do happen.

The other option would be to get an older version of your package, run use_tidy_eval() and document() and then compare the changes. That will be more comprehensive and might catch things I missed above, but the same caveats about not being able to necessarily just reverse everything still apply.

Same strategy for use_pipe().

Sidenote: there are probably ways to adequately qualify different uses of := so that both can coexist in your package, in case that would be preferable.

0
ESELIA On

I known this is an older post but in case others come with a similar problem, I'm posting my answer anyway.

My problem was I mistakenly tried to import into my package a function (fp_border) from a package that it didn't exist in (flextable) [For reference, fp_border() is in the officer package, not flextable] with the function use this::use_import_from().

Not surprisingly, when I ran devtools::check(), I got the error:

object 'fp_border' is not exported by 'namespace:flextable'

The quick fix was to delete the NAMESPACE file for my package, manually edit my package source code ('R/pgkname-package.R') to remove the incorrect roxygen2 comment (#' @importFrom flextable fp_border), and then re-run devtools::document() to generate a fresh NAMESPACE file.