Skip to content
Prev 31055 / 63421 Next

particulars of importing/loading libraries

Simon Urbanek <simon.urbanek at r-project.org> writes:
Imports: rather than Depends: seems like the norm -- the package then
controls its search path, rather than relying on the search path
constructed by the user, and avoids cluttering the user name space and
search path with unnecessary symbols. This would be especially true
for an infrastructure package with many symbols (e.g., RGtk2?) that
might well be irrelevant to an end user.

With Oleg's example, using Imports: allows the package to pass R CMD
check but results in the same error
$Imports
[1] "pack1"

$Depends
[1] "R (>= 2.7.1), methods"
Error in as.POSIXct.default(pack1::testPosixVal) : 
  do not know how to convert 'pack1::testPosixVal' to class "POSIXlt"

This can be remedied by adding exports(as.POSIXct) to the NAMESPACE
file of pack2.

I said above that the Imports: gives the package control of its search
path. This is true for regular symbols
[1] "2009-01-14 03:55:25 UTC"
[1] "POSIXt"  "POSIXct"
[1] "2009-01-14 03:55:25 UTC"

so one might hope that if pack2 Imports: pack1, pack2 would always get
pack1's as.POSIXct methods. Alas, the user writing a method

setMethod("as.POSIXct", signature(x="posixTime"),
          function(x, tz, ...) stop('oops'))

clobers pack2's efforts
Error in as.POSIXct(testPosixVal) : oops

This occurs even when pack2 does not export as.POSIXct (niether method
nor generic), and would seem to be an unfortunate interaction between
methods and name spaces.

Martin

  
    
Message-ID: <6ph63kibke0.fsf@gopher4.fhcrc.org>
In-Reply-To: <E66844FE-E31E-45F4-8753-72445204E7A6@r-project.org> (Simon Urbanek's message of "Tue, 13 Jan 2009 20:50:54 -0500")