From geoff.lee99 at bigpond.com  Wed Nov 26 23:39:32 2014
From: geoff.lee99 at bigpond.com (Geoff Lee)
Date: Thu, 27 Nov 2014 09:39:32 +1100
Subject: [Rd] Problem understanding behaviour of versionCheck for
	loadNamespace (and when versions for Imports packages are checked)
Message-ID: <00ff01d009c9$db1446c0$913cd440$@bigpond.com>

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.

 

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

 

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.

 

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]]



[Rd] Problem understanding behaviour of versionCheck for loadNamespace (and when versions for Imports packages are checked)
Geoff Lee