Many thanks Duncan for the quick response. A bug is a relief in a way. I've been digging my way deeper into this (and learning more as I go) for several days now - but it is a diversion from (a diversion from) my main goal :-(
Is there somewhere specific I should report or log the bug or will that happen from this mailing-list automatically? (I have seen the Bug Tracking link on the r-project page and followed that, but don't yet have a Bugzilla account, nor know the precise mechanics and protocols for notifying a bug) Geoff PS Building package2 - via devtools::build('package2', binary = TRUE) does check and insist that I have an appropriate version of the 'to be imported' package1 installed in my .libPath(). It was only when I simulated a user who has and older version of the Imported package1 (by overwriting the later version of package 1 with an earlier version), then trying to load or attach package2 that the (failure of the version checking) at loadNamespace time for package1 became apparent (well apparentish after quite a bit of digging) -----Original Message----- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: Thursday, 27 November 2014 10:57 AM To: Geoff Lee; r-devel@r-project.org Subject: Re: [Rd] Problem understanding behaviour of versionCheck for loadNamespace (and when versions for Imports packages are checked) Summary: I think you've found a bug. On 26/11/2014, 5:39 PM, Geoff Lee wrote: > Hi > > > > I'm still exploring the R programming universe, so if this is being > asked in the wrong place, or in the wrong way (e.g. too verbose or > lacking in crucial detail or in the wrong format) please let me know > > > > I am trying to understand when the version constraints for packages > which appear in the Imports field of a DESCRIPTION file are checked. I would have assumed they are checked when you try to install the package. If you ask for version 3.0, and only have 0.3, the install should fail. But as you've found, the documents say something else... > > > > Along the way I've hit a snag understanding what loadNamespace with > the versionCheck argument set does. The core of my query is 'am I > doing something wrong, or have I stumbled across a bug?'. Probably > the former, but after several days I still can't figure it out, so any > guidance, hints or outright help would be much appreciated. > > > > Thanks in advance > > > > Geoff > > > > What I've tried so far. > > > > "Writing R extensions" section 1.1.3 says > > > > "The 'Imports' field lists packages whose namespaces are imported from > (as specified in the NAMESPACE file) but which do not need to be attached. ... > shortened for brevity ... Packages declared in the 'Depends' field > should not also be in the 'Imports' field. Version requirements can be > specified and are checked when the namespace is loaded (since R >= 3.0.0). " > > > > It is slightly ambiguous, but seems to mean that the version > dependencies for both Depends packages and Imports packages are > checked when the package > (namespace?) is loaded. > > > > The release notes for R3.0.0 are more direct. They say > > > > "loadNamespace() allows a version specification to be given, and this > is used to check version specifications given in the Imports field > when a namespace is loaded" > > > > But some toy (locally built and loaded) examples seem to show that > while the Depends versions are checked, the Imports version > constraints are not (on Windows 64, running R3.1.2, see full session_info later). > > > > My tests (package2 imports package1) use implicit loading (via the > package1::fun1() idiom) so I have worked back to try get a minimal > example of what's causing me problems. I have tried According to what you have written, that should have failed. So it looks like a bug. > > > > loadNamespace('package2', versionCheck = list (op = ">=", version = > package_version('3.0'))) > > > > This should fail (package2 has version 0.3, not 3.0) but instead it > seems to load package2, version 0.3 OK. > > > > Reading the code of loadNamespace, there is some code which says > > > > if (length(z <- versionCheck) == 3L && !do.call(z$op, > > list(as.numeric_version(version), z$version))) > > stop(gettextf("namespace %s %s is being loaded, but %s %s is > required", > > sQuote(package), version, z$op, z$version), > > domain = NA) > > > > I think it is the length(z <- versionCheck) == 3L part of the if test > that is allowing the incorrect version be loaded. That does seem like a typo. Duncan Murdoch > > > > The documentation for loadNamespace says that "versionCheck" is > > "NULL or a version specification (a list with components op and version))." > > > > If I add a third (nonsense) component to the versionCheck argument > list, then loadNamespace does what I expect. Is there supposed to be > a third component in the list, and if so what should it be? Or is this a bug? > > > > I've got this far and am now stumped, hence my query. > > > > Some output from my tests. > > > > d> devtools::session_info() > > Session > info------------------------------------------------------------------ > -- > > setting value > > version R version 3.1.2 (2014-10-31) > > system x86_64, mingw32 > > ui RStudio (0.98.953) > > language (EN) > > collate English_Australia.1252 > > tz Australia/Sydney > > > > Packages-------------------------------------------------------------- > ------ > ---- > > package * version date source > > devtools 1.6.1 2014-10-07 CRAN (R 3.1.2) > > rstudioapi 0.1 2014-03-27 CRAN (R 3.1.1) > > > > d> # I think this should fail but it does not > > d> loadNamespace('package2', versionCheck = list(op='>=', version = > package_version('3.0'))) > > <environment: namespace:package2> > > > > > > d> devtools::session_info() > > Session > info------------------------------------------------------------------ > -- > > setting value > > version R version 3.1.2 (2014-10-31) > > system x86_64, mingw32 > > ui RStudio (0.98.953) > > language (EN) > > collate English_Australia.1252 > > tz Australia/Sydney > > > > Packages-------------------------------------------------------------- > ------ > ---- > > package * version date source > > devtools 1.6.1 2014-10-07 CRAN (R 3.1.2) > > package2 0.3 2014-11-24 local > > rstudioapi 0.1 2014-03-27 CRAN (R 3.1.1) > > > > d> #Try again with a third (nonsense) entry in the versionCheck list > > d> unloadNamespace('package2') > > d> loadNamespace('package2', versionCheck = list(op='>=', version = > package_version('3.0'), please = 'check it')) > > Error in loadNamespace("package2", versionCheck = list(op = ">=", > version = package_version("3.0"), : > > namespace 'package2' 0.3 is being loaded, but >= 3.0 is required > > > > > > > > d> devtools::session_info() > > Session > info------------------------------------------------------------------ > -- > > setting value > > version R version 3.1.2 (2014-10-31) > > system x86_64, mingw32 > > ui RStudio (0.98.953) > > language (EN) > > collate English_Australia.1252 > > tz Australia/Sydney > > > > Packages-------------------------------------------------------------- > ------ > ---- > > package * version date source > > devtools 1.6.1 2014-10-07 CRAN (R 3.1.2) > > rstudioapi 0.1 2014-03-27 CRAN (R 3.1.1) > > d> loadNamespace('package2', versionCheck = list(op='>=', version = > package_version('0.3'), please = 'check it')) > > <environment: namespace:package2> > > d> > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel