Skip to content

[R-pkg-devel] How to (conditionally) use an archived package (without Suggests)?

7 messages · Marius Hofert, Ben Bolker, Rolf Turner +2 more

#
Thinking a bit about it, the reference to
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Suggested-packages
in the email from CRAN does not really apply in my case. It starts
with "Note that someone wanting to run the examples/tests/vignettes
may not have a suggested package available...", but what I would need
is "Note that someone wanting to run an exported function from the
package may not have a required package available...". It is
essentially the question whether 'code' from a package can be run
'conditionally'. Conceptually, I think it should be possible: If I
want to run a function from zenplots with an argument specifying
specifically to use 'loon', then I should get an error if I don't have
loon installed -- and if I do, then I sure want the code to run.
I ran the check with '--as-cran' without loon available and only got
the above namespace warning, no other warnings or errors. And, of
course, the same on winbuilder.

Cheers,
M

PS: In the meanwhile, I also tried to add 'loon' under
'Additional_repositories' via "Additional_repositories:
https://github.com/waddella/loon", but the check seems to look for a
subfolder of the form ./src/contrib/PACKAGES and that github repos
doesn't seem to have this structure, so I got:

* checking CRAN incoming feasibility ...Warning: unable to access
index for repository https://github.com/waddella/loon/src/contrib:
  cannot open URL 'https://github.com/waddella/loon/src/contrib/PACKAGES'
#
Others may comment more knowledgeably, but I think what you want is
impossible due to the combination
of requirements.

  If you want to put it under additional repositories, I suggest Dirk
Eddelbuettel's drat package as a simple way of
generating the required repository structure.

On Sun, Feb 25, 2018 at 3:49 AM, Marius Hofert
<marius.hofert at uwaterloo.ca> wrote:
#
Marius:

Can you not, instead of
do something like:

if(pkg == "loon" && !requireNamespace("loon", quietly = TRUE)) {
         cat("Package 'loon' is not available.\n")
         cat("Sorry 'bout that, chief!\n")
         return(invisible())
}

Thereby no error is thrown.  The user may be unhappy with the result,
but he or she would have been similarly unhappy with the error, and
there is no way of constructing your function so that such a user *will* 
be happy.

cheers,

Rolf Turner
#
Am Sonntag, 25. Februar 2018, 09:49:13 CET schrieb Marius Hofert:
'Additional_repositories' is meant for R package repositories, it won't work 
with source code git repos. if a package is in 'Suggests' and can't be found 
on CRAN or BioC, the additional repos given here are searched for it, but only 
for it's availability. it won't be installed, CRAN only checks whether it 
*could* be installed.

instead of throwing an error, i would probably fallback to a meaningful 
default at the beginning of the function code and warn the user about it:

  if(pkg == "loon" && !requireNamespace("loon", quietly = TRUE)) {
    pkg == "<no bar>"
    warning(paste(
     "Package 'loon' is unavailable, falling back to the default:", pkg
    ))
  } else {}

i'm dealing with a similar problem at the moment, the main diffenrence being 
that i brought it onto myself by outsourcing specific parts (support for 
several natural languages) of one huge package into several add-on packages, 
and these add-on packages were rejected from CRAN so i can't make any of them 
a dependecy. meaning they're not even archived :-D


viele gr??e :: m.eik
#
On 25 February 2018 at 11:51, meik michalke wrote:
| 'Additional_repositories' is meant for R package repositories, it won't work 
| with source code git repos. if a package is in 'Suggests' and can't be found 

You missed the part where we create packages ("R CMD build") out of source
repos, and then place those packages in package repos.  That is what drat is for.

And with Additional_repositories, it plays with the install.packages() and
update.packages() functions just as it should -- because package dependency
resolution is a powerful mechanism we like to use whereever possible.

Dirk
#
Am Sonntag, 25. Februar 2018, 06:35:52 CET schrieb Dirk Eddelbuettel:
maybe you missed the part where the OP tried to use
https://github.com/waddella/loon in 'Additional_repositories'? AFAIK you can't 
use a simple git source code repository of a package.

i'm maintaining various alternative repos myself ( https://reaktanz.de/R/ ; 
https://files.kde.org/rkward/R/ ; https://undocumeantit.github.io/repos/l10n/ 
) using roxyPackage instead of drat.
do you mean that a dependency is automatically fetched and installed from an 
*alternative* repo configured via 'Additional_repositories'? i didn't get that 
to work. i only ever managed CRAN to see that the package is there during 
checks, but not install it.

take the 'sylly' package:
  https://cran.r-project.org/package=sylly

it has

  Additional_repositories: https://undocumeantit.github.io/repos/l10n

in its DESCRIPTION and suggests 'sylly.de', 'sylly.en', and 'sylly.es'. but 
when i run

  install.packages("sylly", dependencies=TRUE)

i get:

  Warning: dependencies ?testthat?, ?sylly.de?, ?sylly.en?, ?sylly.es? are not
    available

am i missing something?


viele gr??e :: m.eik
#
On 25 February 2018 at 14:20, meik michalke wrote:
| Am Sonntag, 25. Februar 2018, 06:35:52 CET schrieb Dirk Eddelbuettel:
| > On 25 February 2018 at 11:51, meik michalke wrote:
| > | 'Additional_repositories' is meant for R package repositories, it won't
| > | work  with source code git repos. if a package is in 'Suggests' and can't
| > | be found
| > You missed the part where we create packages ("R CMD build") out of source
| > repos, and then place those packages in package repos.  That is what drat is
| > for.
| 
| maybe you missed the part where the OP tried to use
| https://github.com/waddella/loon in 'Additional_repositories'? AFAIK you can't 
| use a simple git source code repository of a package.

It this really so hard?  I have been suggesting, in vain, to _create a
tarball_ and insert said tarball into a package repository precisely because
OP is stuck.

You are not helping by reiterating the OPs position three times over.
 
| do you mean that a dependency is automatically fetched and installed from an 
| *alternative* repo configured via 'Additional_repositories'? i didn't get that 

Yes. We used that for years via drat. And again, no magic.

R tools essentially do that automagically (if dependencies in visible repos
you declared in your session, obviously -- no magic lamps or powder
dust). The dependencies get resolved.  CRAN is no different if you consider
how eg BioConductor gets resolved automagically (and again, see the R Journal
paper for long details if you need them).  Works for source or data packages,
the latter is discussed there.

Dirk