[Rd] Compatibility issue between lme4 and kml (operateur "[")

cgenolin cgenolin at u-paris10.fr
Tue May 26 11:31:42 CEST 2015


Hi all,

There is a compatibility issue between the package 'lme4' and my package
'kml'. I define the "[" operator. It works just fine in my package (1). If I
try to use the lme4 package, then it does no longer work (2). Moreover, it
has some kind of strange behavior (3). Do you know what is wrong? Any idea
of how I can correct that?

Thanks for your help
Christophe

--- 8< ----------------- Code for reproductible example -------------------
library(kml)
dn <- gald(1)
dn["traj"]
library(lme4)
dn["traj"]
setMethod(   ### Simplified version ###
  "[",
  signature=signature(x="ClusterLongData", i="character",
j="ANY",drop="ANY"),
  definition=function (x, i, j="missing", ..., drop = TRUE){
      x <- as(x, "LongData")
      return(x[i, j])
    }
)
dn["traj"]
dn["traj"]

--- 8< ----------------- Execution of the previous code -------------------

> library(kml)
Le chargement a nécessité le package : clv
Le chargement a nécessité le package : cluster
Le chargement a nécessité le package : class
Le chargement a nécessité le package : longitudinalData
Le chargement a nécessité le package : rgl
Le chargement a nécessité le package : misc3d
> dn <- gald(1)

  ###########
 #### (1] ####
### (1) the "[" operator works just fine

> dn["traj"]
      t0   t1    t2    t3    t4   t5   t6    t7    t8    t9   t10
i1 -3.11 4.32  2.17  1.82  4.90 7.34 0.83 -2.70  5.36  4.96  3.16
i2 -7.11 1.40 -2.40 -2.96  4.31 0.50 1.25  0.52 -0.04  7.55  5.50
i3  2.80 6.23  6.08  2.87  2.58 2.88 6.58 -2.38  2.30 -1.74 -3.23
i4  2.24 0.91  6.50 10.92 11.32 7.79 7.78 10.69  9.15  1.07 -0.51

  ###########
 #### (2) ####
### using 'lme4', it does no longer work

> library(lme4)
Le chargement a nécessité le package : Matrix
Le chargement a nécessité le package : Rcpp
> dn["traj"]
Error in x[i, j] : 
  erreur d'évaluation de l'argument 'j' lors de la sélection d'une méthode
pour la fonction '[' : Erreur : l'argument "j" est manquant, avec aucune
valeur par défaut

  ###########
 #### (3) ####
### If I define again the "[", it does not work the first time I call it,
but it work the second time!
> setMethod(
+   "[",
+   signature=signature(x="ClusterLongData", i="character",
j="ANY",drop="ANY"),
+   definition=function (x, i, j="missing", ..., drop = TRUE){
+       x <- as(x, "LongData")
+       return(x[i, j])
+     }
+ )
[1] "["

### No working the first time I use it
> dn["traj"]
Error in dn["traj"] : 
  l'argument "j" est manquant, avec aucune valeur par défaut

### But working the second time
> dn["traj"]
      t0   t1    t2    t3    t4   t5   t6    t7    t8    t9   t10
i1 -3.11 4.32  2.17  1.82  4.90 7.34 0.83 -2.70  5.36  4.96  3.16
i2 -7.11 1.40 -2.40 -2.96  4.31 0.50 1.25  0.52 -0.04  7.55  5.50
i3  2.80 6.23  6.08  2.87  2.58 2.88 6.58 -2.38  2.30 -1.74 -3.23
i4  2.24 0.91  6.50 10.92 11.32 7.79 7.78 10.69  9.15  1.07 -0.51






--
View this message in context: http://r.789695.n4.nabble.com/Compatibility-issue-between-lme4-and-kml-operateur-tp4707670.html
Sent from the R devel mailing list archive at Nabble.com.



More information about the R-devel mailing list