Skip to content
Prev 8015 / 63424 Next

Installing packages using methods: was Re: setGeneric(); R CMD check

David James wrote:
By "binary", meaning "INSTALL --save" or equivalent?

Yes, and the symptom you mentioned is rather mild, compared to what will
often happen!  Any of the computations that default to assigning
metadata to the global environment will cause problems (setMethod,
setClass, ...) in a default installation, unless all such computations
are wrapped in a function call that can be re-directed from the
.First.lib function to the correct environment.

It's not likely to be worth the effort.

For the present version of R, the simplest approach is probably for the
programmer to arrange for an installation with a saved image, either
through the option to INSTALL or by putting a file "install.R" (an empty
file will do) in the top source directory of the package.

For the next version, we should try to make the process more automatic,
although the only way that would always work seems to be by making
--save the default to INSTALL.
...................

As mentioned, the "CMD check"  problem may be the least of it!

The following snippet will _apparently_ install with or without --save:

### Dummy Package
require("methods")

foo <- function(x)x

setGeneric("foo")

setMethod("foo", "character", function(x) paste("++", x))
###

But in the default install, it fails (annoyingly) when the library is
attached, because the assignment of foo is not in the search list, so
setGeneric doesn't find any definition of "foo".


R> library(DummyPackage)
Loading required package: methods 
Error in setGeneric("foo") : Must supply a function skeleton, explicitly
or via an existing function


It's possible to work around most of the specific problems, but my
feeling is that the natural semantics for the programmer is that  the
same source code should work basically the same way, whether being
sourced into the global environment for initial testing or being
installed as a package.
Yes.  I'll add it to the online help for INSTALL (& the extensions
document?).

John