Conte-Ecology / conteStreamTemperature

Package for cleaning and analyzing stream daily stream temperature
MIT License
1 stars 1 forks source link

Package dependencies #6

Closed djhocking closed 9 years ago

djhocking commented 10 years ago

When checking the package I get the following warning

* checking dependencies in R code ... WARNING
'library' or 'require' call not declared from: 'ggmap'
'library' or 'require' calls to packages already attached by Depends:
  'ggplot2' 'gridExtra' 'reshape2' 'sp'
  Please remove these calls from your code.
Packages in Depends field not imported from:
  'DataCombine' 'dplyr' 'ggplot2' 'gridExtra' 'knitr' 'lubridate'
  'reshape2' 'rjags' 'rmarkdown' 'sp'
  These packages need to be imported from (in the NAMESPACE file)
  for when this namespace is loaded but not attached.

I don't (can't) modify NAMESPACE because it is automatically generated by roxygen2. I tried reading the Writing R packages manual but am not clear what to put in Depends and then if those are needed in library() or require() calls within functions.

http://cran.r-project.org/doc/manuals/r-release/R-exts.html#Package-Dependencies

Should I be using Imports instead of Depends?

Packages whose namespace only is needed to load the package using library(pkgname) should be 
listed in the ‘Imports’ field and not in the ‘Depends’ field. Packages listed in imports or 
importFrom directives in the NAMESPACE file should almost always be in ‘Imports’ and not ‘Depends’. 
walkerjeffd commented 10 years ago

Yeah, I can never figure out what the Writing R Packages manual is saying. So when in doubt, look at one of hadley wickhams' packages. I just looked at tidyr and in his DESCRIPTION the only thing under Depends is the R version. Then all the packages used by the library are under Imports.

Then in the source code, he never actually calls require() or library() so I think as long as the packages are listed under Imports in DESCRIPTION then they get loaded automatically.

But I think its supposed to be good practice to namespace the functions used from other packages with ::. Like if you wanted to use the ggplot() function from ggplot2 then you would write ggplot2::ggplot() in the source code. This specifies that ggplot comes from ggplot2. See Line 31 of gather.R where he uses dplyr::select_vars but never calls library(dplyr).

anarosner commented 10 years ago

I've read a few things recently that might be helpful. I actually started looking into this because I had an issue with calling specific versions of packages, not really about imports/depends. But, they cover that.

http://obeautifulcode.com/R/How-R-Searches-And-Finds-Stuff/ http://stackoverflow.com/questions/8637993/better-explanation-of-when-to-use-imports-depends

The first link is incredibly thorough. Sections I've read so far have been helpful; a thorough read-through is on my to-do list.

All that being said, I'm current using Depends... the word I'm currently using in my DESCRIPTION file uses the word "Depends". Works fine for now, but I'll gladly change that if consensus moves in that direction.

Thanks, Ana