Installing the dependency packages

Hello!

I am working on my first package and I am trying to understand how does the devtools::install_github() (or in general install.packages - if the packages on the imports or the depends list of the DESCRIPTION file of the package are already installed why it reinstall it again? I am getting error when it tried to remove existing packages and reinstall them back.

Thank you in advance!
Rami

Here is a great ressource when developping package :


http://r-pkgs.had.co.nz/

There is a part on dependencies : http://r-pkgs.had.co.nz/description.html

Imports: packages listed here must be present for your package to work. In fact, any time your package is installed, those packages will, if not already present, be installed on your computer (devtools::load_all() also checks that the packages are installed).
Adding a package dependency here ensures that it’ll be installed.

If the package are already installed, it should not reinstalled them.

What is your workflow ? Is your package available somewhere ? at which step did you observe a reinstallation?

Indeed this book is a great resource for first package development.

The reinstallation of some of the packages (dplyr, data.table, lubridate, etc.) occur when using the installation from github using devtools:

devtools::install_github("RamiKrispin/MLstudio") 

With respect of package installation (not loading), is there a different if a package is under imports or depends?

Thanks!
Rami

You can also find some informations on dependencies in CRAN manual Writing R extensions
One major difference:

  • Packages in depends fields are attached in the R sessions

The ‘Depends’ field gives a comma-separated list of package names which this package depends on. Those packages will be attached before the current package when library or require is called

  • Packages in Imports are not attached but namespace is known and loaded.

The ‘Imports’ field lists packages whose namespaces are imported from (as specified in the NAMESPACE file) but which do not need to be attached.

You'll find this explanation in the Namespace part of R package book too. Moreover, Depends was the old way to specify packages.

Prior to the rollout of namespaces in R 2.14.0, Depends was the only way to “depend” on another package.

The advice is to minimise the impact of your package on the global environment of your user. Putting a package in Depends will make this package attached when a call to library(MLstudio) is made - it will change the search path. Not a good practice to be invasive on a user session and all the more if you could do otherwise. It is why it is better to use Imports instead.

Maybe you should try to put them all in Imports field and see if it reinstalled them also ?
Could be another difference between Depends and Imports at installation.

Yes, this is the plan, to move most of the packages for the imports to minimize the impact on the global environment. Thank you for all the information!!!