2

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()?

Jollywatt
  • 1,382
  • 2
  • 12
  • 31

2 Answers2

1

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.

Calum You
  • 14,687
  • 4
  • 23
  • 42
  • Man. This is exactly the answer I didn’t want to get. I thought `usethis` made things easy, but if undoing actions requires understanding of inner workings of packages anyway, it might not be that useful. I’ll hold of on accepting this for a bit in case someone else has suggestions. – Jollywatt Aug 31 '22 at 00:24
  • 1
    `usethis` handles the above steps for you which is already a big time save, but if you're writing a package you probably want to understand what the different parts of the package do. The point is that the actions it takes are not necessarily reversible - e.g. if you already ran `use_package("roxygen")` to add roxygen to `DESCRIPTION`, `use_tidy_eval` doesn't add it twice, and if you want to remove tidy eval then you don't want to remove things that other parts of the package still need. – Calum You Sep 01 '22 at 20:21
1

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.

ESELIA
  • 132
  • 1
  • 12