Skip to content

as.vector in R-devel loaded 3/3/2016

7 messages · Jeff Laake, Peter Dalgaard, Martin Morgan +1 more

#
I just installed R-devel to check my package before submitting.  I got an
error in my vignette in regards to as.vector.  When I looked at the code
for as.vector in R-devel it is

standardGeneric for "as.vector" defined from package "base"

function (x, mode)
standardGeneric("as.vector")
<environment: 0x0918ad70>
Methods may be defined for arguments: x, mode
Use  showMethods("as.vector")  for currently available ones.

The code from R3.2.3 is
function (x, mode = "any")
.Internal(as.vector(x, mode))
<bytecode: 0x02dfb858>
<environment: namespace:base>
Is default for mode missing as I suspect or will mode be required from now
on?
#
I dug into this a little further and discovered the problem.  When my
package is for checking, it loads Matrix.  In the R-devel version of
Matrix, as.vector is re-defined without mode specified
standardGeneric for "as.vector" defined from package "base"

function (x, mode)
standardGeneric("as.vector")
<environment: 0x082faf08>
Methods may be defined for arguments: x, mode
Use  showMethods("as.vector")  for currently available ones.

In R3.2.3 it is defined with mode="any" specified.
standardGeneric for "as.vector" defined from package "base"

function (x, mode = "any")
standardGeneric("as.vector")
<environment: 0x084af110>
Methods may be defined for arguments: x, mode
Use  showMethods("as.vector")  for currently available ones.

Until this is fixed I'll copy over the devel version of Matrix.

--jeff


On Thu, Mar 3, 2016 at 7:23 AM, Jeff Laake - NOAA Federal <
jeff.laake at noaa.gov> wrote:

            

  
  
#
Er, until _what_ is fixed?

I see no anomalies with the version in R-pre:
standardGeneric for "as.vector" defined from package "base"

function (x, mode = "any") 
standardGeneric("as.vector")
<environment: 0x7fe8f4516640>
Methods may be defined for arguments: x, mode
Use  showMethods("as.vector")  for currently available ones.
int [1:3] 1 2 3
num [1:3] 1 2 3
+ )
List of 3
 $ : num 1
 $ : num 2
 $ : num 3
int [1:3] 1 2 3
num [1:3] 1 2 3


Also, *current* r-devel has the same definition:

$ ~/r-devel/BUILD-dist/bin/R

R Under development (unstable) (2016-03-03 r70270) -- "Unsuffered Consequences"
[...yadayada...]
function (x, mode = "any") 
.Internal(as.vector(x, mode))
<bytecode: 0x7fdf69279780>
<environment: namespace:base>

  
    
#
> Er, until _what_ is fixed?
    > I see no anomalies with the version in R-pre:

Indeed.

The problem ... I also have stumbled over ..
is that I'm sure Jeff is accidentally loading a different
version of 'Matrix' than the one that is part of R-devel.

Jeff you must accidentally be loading a version Matrix made with
R 3.2.x in R 3.3.0  and that will fail with the as.vector()
mismatch error message.

(and IIRC, you also get such an error message if you load a
 3.3.0-built version of Matrix into a non-3.3.0 version of R).


Martin
#
I see as below, where getGeneric and getMethod imply a different signature; the signature is mode="any" for both cases in R version 3.2.3 Patched (2016-01-28 r70038)I don't know how to reproduce Jeff's error, though.
function (x, mode = "any") 
.Internal(as.vector(x, mode))
<bytecode: 0xe79f88>
<environment: namespace:base>
standardGeneric for "as.vector" defined from package "base"

function (x, mode) 
standardGeneric("as.vector")
<bytecode: 0x29a6bd0>
<environment: 0x299f988>
Methods may be defined for arguments: x
Use  showMethods("as.vector")  for currently available ones.
Method Definition (Class "internalDispatchMethod"):

function (x, mode) 
.Internal(as.vector(x, mode))
<environment: base>

Signatures:
        x    
target  "ANY"
defined "ANY"
R Under development (unstable) (2016-02-27 r70232)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.4 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Matrix_1.2-4

loaded via a namespace (and not attached):
[1] grid_3.3.0      lattice_0.20-33
#
Thanks. Indeed I was having a permission issue installing/updating packages
and had put a version of Matrix in my personal library which must have been
getting loaded ahead of the one in revel library. Sorry for the bother.

On Friday, March 4, 2016, Morgan, Martin <Martin.Morgan at roswellpark.org>
wrote:

  
  
#
> I see as below, where getGeneric and getMethod imply a different signature; the signature is mode="any" for both cases in R version 3.2.3 Patched (2016-01-28 r70038)I don't know how to reproduce Jeff's error, though.

    >> library(Matrix)

    >> as.vector
    > function (x, mode = "any") 
    > .Internal(as.vector(x, mode))
    > <bytecode: 0xe79f88>
    > <environment: namespace:base>

so note, that even though Matrix is loaded, as.vector did not
have to change to a standardGeneric(.).

"The" reason is list among the NEWS  for R-devel :

 o   S4 dispatch works within calls to .Internal(). This means explicit
     S4 generics are no longer needed for unlist and as.vector.  

so this change was very much on purpose and has had the goal to
keep as.vector() "as fast as possible".

*BUT* indeed, the "signature mismatch" you observe has been
an bogous side effect of the change, and it may even be the
reason why versions of Matrix built in different versions of R
(3.2.x  vs  3.3.x) are problematic.

I'll commit a fix for this buglet {which also affects 'unlist' !} 
in a moment.

So after all, I'm very glad for this thread!
Martin

    >> getGeneric("as.vector")
    > standardGeneric for "as.vector" defined from package "base"

    > function (x, mode) 
    > standardGeneric("as.vector")
    > <bytecode: 0x29a6bd0>
    > <environment: 0x299f988>
    > Methods may be defined for arguments: x
    > Use  showMethods("as.vector")  for currently available ones.
    >> selectMethod("as.vector", "ANY")
    > Method Definition (Class "internalDispatchMethod"):

    > function (x, mode) 
    > .Internal(as.vector(x, mode))
    > <environment: base>

    > Signatures:
    > x    
    > target  "ANY"
    > defined "ANY"
    >> sessionInfo()
    > R Under development (unstable) (2016-02-27 r70232)
    > Platform: x86_64-pc-linux-gnu (64-bit)
    > Running under: Ubuntu 14.04.4 LTS

    > locale:
    > [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
    > [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
    > [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
    > [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
    > [9] LC_ADDRESS=C               LC_TELEPHONE=C            
    > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

    > attached base packages:
    > [1] stats     graphics  grDevices utils     datasets  methods   base     

    > other attached packages:
    > [1] Matrix_1.2-4

    > loaded via a namespace (and not attached):
    > [1] grid_3.3.0      lattice_0.20-33