Search code examples
rr-package

How to properly include dependencies in the DESCRIPTION file of R package?


I am writing an R package and here:

R package does not load dependencies

A user indicates that (s)he changed

Imports: dplyr (>= 0.4.3), ggplot2 (>= 2.1.0), lazyeval (>= 0.1.10)

to

Depends: dplyr (>= 0.4.3), ggplot2 (>= 2.1.0), lazyeval (>= 0.1.10)

And the problem with required packages for a new R package was solved. However, that person did not indicate if the change was done manually or by coding. I am doing the change manually and my problem persists (and I really believe the problem is about importing packages or dependencies).

My questions are:

  1. Is it just fine to edit the DESCRIPTION file manually? If not,
  2. Which is the proper way to do the change?

Very much thank you in advance


Solution

  • To answer your questions:

    (1) It is fine to update the DESCRIPTION file manually.

    (2) There is no "proper way" to do this, but I find that the best way to add an R-package as an import is to use usethis::use_package("package"). This will add it to the correct place in the DESCRIPTION file, and will remind you to reference the packages you use as package::function() (which is needed, as the Imports field only load, and don't attach, the packages).

    Regarding putting a package in Depends vs. Imports: you should almost always put packages your code relies on as Imports. You can read more about it here.

    I hope this was useful.