Imported packages do not auto-install - r

I have a private package stored locally (and version-controlled via SVN). To install the package, I am asking the user to SVN-update his/her package directory, then setwd() on the directory, and then devtools::install().
This package imports many CRAN packages, which are not stored locally. These imported packages are not auto-installing during the installation, which produces the error message Dependency package foo not available. The user must manually install install.packages('foo'), then try again, only to get Dependency package bar not available, ad nauseam, even though foo and bar are among my Imports:
Details:
My DESCRIPTION file looks like:
Package: apackage
Type: Package
Title: Package to Do Stuff
Version: 1.11111
Date: 2017-03-02
Author: C8H10N4O2
Maintainer: C8H10N4O2<C8H10N4O2#example.com>
Description: Package that does many useful things
License: file LICENSE
Depends:
R (>= 3.3.0)
Imports:
bit64 (>= 0.9.5),
data.table (>= 1.9.6),
extrafont (>= 0.17),
foreach(>= 1.4.3),
ggplot2 (>= 2.0.0),
gbm (>= 2.1),
grid (>= 3.2.3),
gridExtra (>= 2.0.0),
httr (>= 1.1.0),
readxl (>= 0.1.1),
scales (>= 0.4.0),
xlsx (>= 0.5.7)
LazyData: true
RoxygenNote: 5.0.1
Suggests: testthat (>= 0.9.1)
But upon invoking check() or load_all() I still get the error:
Error in (function (dep_name, dep_ver = NA, dep_compare = NA) :
Dependency package gridExtra not available.
And then my user has to install.packages('gridExtra'), and then he/she gets another dependency not available error.
What I have tried:
According to R packages:
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).
I also checked Writing R Extensions but couldn't find anything else on this topic.
Am I correct that these packages should be auto-installing, and what should I do to ensure that they auto-install?
I recognize that the problem is not fully reproducible, but I can't link to my repo, so I'm happy to provide any additional details.
**versions**
R 3.4.0, platform = x86_64-w64-mingw32
devtools 1.13.1

You are reinventing packaging with R. I advise against. You could just drat to create a repository. This is tried and true and works.
And this deployment aspect, for both production of local packages as well as their use and installation is entirely orthogonal to where you keep sources. Don't mistake a source code repository for code distribution mechanism.
In sum, using drat locally along with local GitHub Enterprise instance has worked swimmingly for us at work, and drat in general is in fairly widespread use.
(Usual disclaimers as I am the one who started drat, but I had the good fortune of a bunch of contributors too.)

Related

Know which (exact) R version a package was built under?

How can we tell precisely which R version an R package was built under?
Example
In the RSelenium package's DESCRIPTION file here, we see
Depends:
R (>= 3.0.0)
But this does not appear to be precise (due to the > symbol)
Notes
Karl Browman's site says that:
Depends is used to indicate dependency on a particular version of R, and on packages that are to be loaded (with library()) whenever your package is loaded. If you expect that users would want to load that other package whenever they loaded yours, then you should include the package name here. But this is now relatively rare. (I think the namespaces for these packages should also be imported, with #import.)
It almost never matters which version built a package. The only thing that usually matters is which version installed it. (Binary packages are images of installed packages, so it matters for them.)
The version that installed a package is stored in the Built: field in the DESCRIPTION file. (Yes, "Built", not "Installed".)
You can see it using code like
read.dcf(system.file("DESCRIPTION", package="base"), fields="Built")
#> Built
#> [1,] "R 3.6.1; ; 2019-07-06 02:01:41 UTC; unix"
Put in your own package name instead of "base".
The exception for the "almost never matters" is on those rare occasions when the package format changes.

Issues building and installing a created R package

I have created an R package (not yet on CRAN) and sent it to a colleague (as a .zip file).
Unfortunately, they were unable to properly build/install it without R throwing an error.
The error received was:
Error: Command failed (1)
In addition: Warning message:
The following packages are referenced using Rcpp::depends attributes however are not listed in the Depends, Imports or LinkingTo fields of the package DESCRIPTION file: RcppProgress
To create the package, I used the RcppArmadillo.package.skeleton() function in R v. 3.4.3.
I works for me, but not for my colleague.
My method in building/installing is:
build("package name") # creates a .tar.gz file
install("package name")
Would simply sending the .tar.gz file to my colleague and simply running install() work?
Here is the DESCRIPTION file:
Package: HACSim
Type: Package
Title: Iterative simulation of species haplotype accumulation curves
Version: 1.0
Date: 2018-04-06
Author: Jarrett Phillips
Maintainer: Jarrett Phillips
Description: Iterative simulation of species haplotype accumulation curves for assessment of sampling completeness
License: GPL (>= 3)
NeedsCompilation: Yes
Imports: ape (>= 5.0),
boot (>= 1.3-20),
investr (>= 1.4.0),
mgcv (>= 1.8-23),
pegas (>= 0.10),
Rcpp (>= 0.12.16),
scam (>= 1.2-2)
LinkingTo: Rcpp,
RcppArmadillo
and NAMESPACE
useDynLib(HACSim, .registration=TRUE)
importFrom(Rcpp, evalCpp)
importFrom(ape, base.freq)
importFrom(ape, read.dna)
importFrom(boot, boot)
importFrom(boot, boot.ci)
importFrom(investr, predFit)
importFrom(MASS, mvrnorm)
importFrom(mgcv, gam)
importFrom(mgcv, gam.check)
importFrom(mgcv, predict.gam)
importFrom(pegas, haplotype)
importFrom(rootSolve, uniroot.all)
importFrom(rootSolve, multiroot)
importFrom(scam, scam)
importFrom(scam, scam.check)
importFrom(scam, predict.scam)
exportPattern("^[[:alpha:]]+")
The error is
The following packages are referenced using Rcpp::depends attributes \
however are not listed in the Depends, Imports or LinkingTo fields of\
the package DESCRIPTION file: RcppProgress
which seems plausible given what you now posted for DESCRIPTION and NAMESPACE.
So here is what I would do:
Create the package using the skeleton generator as you have. Extend as neeed as you have. Then ...
Run R CMD build mypackage then
Run R CME check mypackage_1.2.3.tar.gz
This should give you a clear idea as to whether your sources are in good shape. After that, you can create a binary or zip or ... which your colleague should be able to utilise.
Edit: And you should of course grep for RcppProgress upon which you may indeed have an undeclared dependency.

Adding dependencies properly to an r package, so that they install automatically

I'm making my first R package, and I'm trying to include package dependencies. The package installs and works fine on my machine, but I already have all of the dependencies installed. When another user attempts to install and they do not have all the dependencies already installed, they get an error.
ERROR: dependency 'dplyr' is not available for package 'my_package'
I am documenting the package via roxygen2.
I know I'm supposed to include #'#import lines in my /R files, and they get added automatically to the DESCRIPTION and NAMESPACE files.
My DESCRIPTION file looks like this:
Package: my_package
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors#R: person("First", "Last", email = "first.last#example.com", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: R (>= 3.4.1)
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
Imports: dplyr,
descr
And my NAMESPACE looks like this:
export(my_function)
import(descr)
import(dplyr)
The user is installing the package locally with:
install.packages("C:/custom_packages/my_package_0.0.0.9000.tar.gz/", repos = NULL, type = "source")
Answers I've read on this topic say that having the proper import statements in the DESCRIPTION and NAMESPACE should be all you need to document dependencies, which I have here. The behavior for most CRAN packages I've installed is that if there is a dependency that is not installed, it installs along with the installation. What steps am I missing so that my package mimics this behavior?
A good strategy when it comes to developing your first packages is, in my experience, checking the work of others. The easiest way to do that is to check some of your favorite packages on Github. Here is, for example, a part of one of my DESCRIPTION files:
Depends:
R (>= 3.3.0)
License: GPL-3
Imports:
stringi (>= 1.1.7),
data.table (>= 1.10.4.3),
methods (>= 3.3.0),
quanteda (>= 1.1.0),
scales (>= 0.5.0),
stats (>= 3.3.0),
utils (>= 3.3.0)
As you can see, every package has a minimal version (most of them are simply the versions I use but for some, I tested if older versions work). And I use Imports to mark packages and Depends only to indicate the oldest R version which I successfully tested. You should almost always use Imports or Suggests instead of Depends for packages.
Once you have set this up, you can run:
# This should point to the folder of your DESCRIPTION file
setwd("/path/to/your/package/")
roxygen2::roxygenise(clean = TRUE)
Do not alter the NAMESPACE directly! This should be enough to install your package or put it on GitHub.
However, this is just the tip of the iceberg and it would probably be a good idea to check this post out and then read up on the details in this book.
Update: Given the comment from #Benjamin, I see that I have missed one part of your question. repos = NULL, type = "source" suppresses the installation of dependencies. A better way would be to use devtools. I'm not sure if this is the correct way, but when I already have a tarball and need to install it I use something like:
# In Windows use copy and paste directly on the file to get a link
devtools::install_url("C:/custom_packages/my_package_0.0.0.9000.tar.gz")

R package dependencies not installed from Additional_repositories (revisited)

I am attempting to prepare a package for submission to the CRAN. In my DESCRIPTION file I include non-CRAN packages in the Depends and Suggests arguments. To tell R where to find the non-CRAN packages, I include the Additional_repositories argument; and I include an .onLoad function at the top of my program (i.e., in 'zzz.R'). I am able to build and check (--as-cran) in RStudio with zero warnings, notes or errors so long as all the Depends and Suggests packages are present. I then use devtools::build() to create a .tar.gz file locally.
To test for a successful local install, I remove the non-CRAN packages from my computer and attempt to install the .tar.gz file that I created. I then get the message:
ERROR: dependency 'smwrQW' is not available for package 'baytrends'
I've read through the
R package dependencies not installed from Additional_repositories
Include non-CRAN package in CRAN package
http://thecoatlessprofessor.com/programming/r-data-packages-in-external-data-repositories-using-the-additional_repositories-field/
How should I deal with "package 'xxx' is not available (for R version x.y.z)" warning?
Unfortunately, the above error continues. I'm confident of the url I'm using since the below install.package line works when run independently
install.packages('smwrQW',repos=c("http://owi.usgs.gov/R"),dependencies = TRUE)
The applicable bits of the DESCRIPTION and zzz.R file are below:
DESCRIPTION:
Date: 2017-03-15
Depends:
R (>= 3.2.0),
lubridate,
mgcv,
smwrQW
License: GPL-3
LazyData: TRUE
RoxygenNote: 6.0.1
Suggests:
dataRetrieval,
devtools,
fitdistrplus,
knitr,
nlme,
pander,
plyr,
rmarkdown,
smwrBase,
smwrGraphs,
smwrStats,
testthat
Additional_repositories: http://owi.usgs.gov/R
VignetteBuilder: knitr
zzz.R:
.onLoad <- function(libname = find.package("baytrends"), pkgname = "baytrends"){
repos = getOption("repos")
repos["USGS"] = "http://owi.usgs.gov/R"
options(repos = repos)
invisible(repos)
# declaration of global variables (https://stackoverflow.com/questions/9439256)
if(getRversion() >= "2.15.1")
utils::globalVariables(c("begin", "methodsList"))
invisible()
}
.onAttach <- function(libname = find.package("baytrends"), pkgname = "baytrends"){
packageStartupMessage("This software program is preliminary or provisional and is subject to revision. ")
}
You cannot have packages from non-standard repos in Depends: or Imports:.
You can have them in Suggests:
Several packages do this; one you could look at is hurricaneexposure which uses this to make a 'too-large-for-CRAN' data package hurricanexposuredata available from a repository created via drat.
So you must move the smwrQR package to Suggests: and then test for it.
Brooke and I have a draft paper (under review) on this which we could send you if you drop us line -- it details all this more than the short answer could.

What are "reverse dependencies" in R?

I have to install the rjson package in R and looking at the CRAN page that deals with the package I saw that rjson has different dependencies:
Reverse depends: couchDB, df2json, edeR, gooJSON, indicoio, kintone, notifyR, RDSTK, Rfacebook, rJython, Rlabkey, rPlant, RYoudaoTranslate, SmarterPoland, sotkanet, source.gist, Storm, streamR, tibbrConnector, zendeskR;
Reverse imports: AntWeb, argparse, BerlinData, blsAPI, Causata, d3Network, db.r, geonames, GetoptLong, ggmap, h2o, helsinki, james.analysis, meteoForecast, mpoly, networkD3, ngramr, nhlscrapr, OpasnetUtils, OutbreakTools, paleobioDB, RAdwords, rbefdata, rClinicalCodes, rfisheries, rglobi, RIGHT, rnrfa, solr, StereoMorph, structSSI, twitteR, vdmR, yhatr;
Reverse suggests: fuzzyMM, GSIF, installr, mlr, plotKML, rsnps, sorvi, trajectories;
What is the difference among them and do I have to install all of them to use the rjson package?
These are reverse dependencies, that is these packages depend on rjson.
You do not have to install these in order to use rjson.
Looking at the DESCRIPTION file (this is where the dependencies are stated) you see only:
Depends: R (>= 3.1.0)
So rjson package needs only R newer or equal than 3.1.0 to run.
Just as EDi has stated, the list states packages that depend on rjson.
I think kintone has been knocked off the list, since the cloud service itself is not dependent on rjson. The R SDK for kintone though, is dependent on rjson, as shown in the README of the GitHub page.
So in this case, if I wanted to run kintone's APIs using this R SDK, I would also need the rjson package for it to work properly.

Resources