Hi Joris,

Adding importMethodsFrom(lme4.0,summary) to the NAMESPACE solved the problem.

Best regards,

Thierry

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx@inbo.be<mailto:Thierry.Onkelinx@inbo.be>
www.inbo.be<http://www.inbo.be/>

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

Van: Joris Meys [mailto:jorismeys@gmail.com]
Verzonden: donderdag 3 april 2014 15:18
Aan: ONKELINX, Thierry
CC: Joshua Wiley; r-devel@r-project.org
Onderwerp: Re: [Rd] summary of lme4.0 model in package

Thierry,

did you try to importFrom() in the namespace file? That way you know for sure you have the correct summary function in the namespace of your package. Since namespaces are available, I personally found that using them whenever possible/suitable can prevent a lot of conflicts due to similarly named functions. In this case you notice the difference in search path. If you call a function within a package (package:function), it will look for the summary function in the namespaces and imported namespaces first. If you source it on the other hand, it will look for the summary function in the attached packages first. And in your case, that's 2 different versions of the same function.

You will keep on having this problem as long as your package directly or indirectly calls for 2 different versions of the same package. I fail to understand why you would make your package dependent on an old version of lme4 (i.e. lme4.0). Back compatibility between new and old versions of lme4 are not guaranteed.

Cheers
Joris

On Thu, Apr 3, 2014 at 2:55 PM, ONKELINX, Thierry <Thierry.ONKELINX@inbo.be<mailto:Thierry.ONKELINX@inbo.be>> wrote:
An update: I copied the functions from package A into MyPackage instead of importing them. This avoids lme4_1.1-5 to be loaded via namespace (see sessionInfo). However, the error remains. Nlme is loaded via namespace by lme4.0

R version 3.0.2 (2013-09-25)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Dutch_Belgium.1252  LC_CTYPE=Dutch_Belgium.1252    LC_MONETARY=Dutch_Belgium.1252
[4] LC_NUMERIC=C                   LC_TIME=Dutch_Belgium.1252

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

other attached packages:
[1] sendmailR_1.1-2   base64enc_0.1-1   ABV_0.2-21        lme4.0_0.999999-4 lattice_0.20-28   Matrix_1.1-3

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4   dichromat_2.0-0    digest_0.6.4       fortunes_1.5-2     ggplot2_0.9.3.1.99 grid_3.0.2
 [7] gridExtra_0.9.1    gtable_0.1.2       labeling_0.2       lubridate_1.3.3    MASS_7.3-30        memoise_0.1
[13] multcomp_1.3-2     munsell_0.4.2      mvtnorm_0.9-9997   nlme_3.1-115       plyr_1.8.1         proto_0.3-10
[19] RColorBrewer_1.0-5 Rcpp_0.11.1        reshape2_1.2.2     RODBC_1.3-10       sandwich_2.3-0     scales_0.2.3
[25] splines_3.0.2      stats4_3.0.2       stringr_0.6.2      survival_2.37-7    TH.data_1.0-3      tools_3.0.2
[31] zoo_1.7-11

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx@inbo.be<mailto:Thierry.Onkelinx@inbo.be>
www.inbo.be<http://www.inbo.be>

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey


-----Oorspronkelijk bericht-----
Van: ONKELINX, Thierry
Verzonden: donderdag 3 april 2014 13:44
Aan: 'Joshua Wiley'
CC: r-devel@r-project.org<mailto:r-devel@r-project.org>
Onderwerp: RE: [Rd] summary of lme4.0 model in package

Dear Joshua,

Thank you for quick reply.

Note that my package has Depends: lme4.0 in DESCRIPTION. It imports and suggests other packages but not lme4. lme4_1.1-5 is attached because my package imports (via Imports: in DESCRIPTION) functions from package A, which imports (via Imports: in DESCRIPTION) functions from package B, which imports (via Imports: in DESCRIPTION) functions from lme4. Neither packages A nor B import lme4 related functions.

Should try to import lme4.0 instead of depending on it?

Best regards,

Thierry

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx@inbo.be<mailto:Thierry.Onkelinx@inbo.be>
www.inbo.be<http://www.inbo.be>

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

Van: Joshua Wiley [mailto:jwiley.psych@gmail.com<mailto:jwiley.psych@gmail.com>]
Verzonden: donderdag 3 april 2014 12:36
Aan: ONKELINX, Thierry
CC: r-devel@r-project.org<mailto:r-devel@r-project.org>
Onderwerp: Re: [Rd] summary of lme4.0 model in package

Dear Thierry,

You have lme4.0_0.999999-4 attached and  lme4_1.1-5 loaded via a namespace.  I wonder if changes between the versions and which was getting called when are making the difference.  In particular, when you source it, I would assume methods from the attached package are used.  When you use the function from the package, the methods from the dependencies for the package would be used.

Cheers,

Josh



On Thu, Apr 3, 2014 at 3:09 AM, ONKELINX, Thierry <Thierry.ONKELINX@inbo.be<mailto:Thierry.ONKELINX@inbo.be>> wrote:
Dear all,

My package has Depends: lme4.0 in the DESCRIPTION. I need to extract the fixed effect of a model and their standard errors. I use coef(summary(model)) inside a function to do that. Model is the output of a call to glmer() from the lme4.0 package.

coef(summary(model)) throws an error: $ operator is invalid for atomic vectors

I have tracked it down to a problem with summary(model) because str(summary(model)) gives this

Classes 'summaryDefault', 'table'  Named chr [1:3] "1" "mer" "S4"
  ..- attr(*, "names")= chr [1:3] "Length" "Class" "Mode"

But it should return

Formal class 'summary.mer' [package "lme4.0"] with 42 slots
  ..@ methTitle: chr "Generalized linear mixed model fit by the Laplace approximation"
  ..@ logLik   :Class 'logLik' : -2265 (df=12)
--- output snipped ---

What puzzles me is that the function gives the error when called from the package, but works fine when I source the code of the function manually.

#this fails
MyPackage:MyFunction(model)
#this works
source("MyPackage/R/MyFunction.R")
MyFunction(model)

Any idea on what is going wrong and how to fix this?

sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Dutch_Belgium.1252  LC_CTYPE=Dutch_Belgium.1252    LC_MONETARY=Dutch_Belgium.1252 [4] LC_NUMERIC=C                   LC_TIME=Dutch_Belgium.1252

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

other attached packages:
[1] sendmailR_1.1-2   base64enc_0.1-1   ABV_0.2-21        lme4.0_0.999999-4 lattice_0.20-28   Matrix_1.1-3

loaded via a namespace (and not attached):
 [1] AFLP_0.4.0-66       colorspace_1.2-4    dichromat_2.0-0     digest_0.6.4        Epi_1.1.63
 [6] fortunes_1.5-2      ggplot2_0.9.3.1.99  grid_3.0.2          gridExtra_0.9.1     gtable_0.1.2 [11] labeling_0.2        lme4_1.1-5          lubridate_1.3.3     MASS_7.3-30         memoise_0.1 [16] mgcv_1.7-28         minqa_1.2.3         multcomp_1.3-2      munsell_0.4.2       mvtnorm_0.9-9997 [21] nlme_3.1-115        permute_0.8-3       plyr_1.8.1          proto_0.3-10        RColorBrewer_1.0-5 [26] Rcpp_0.11.1         RcppEigen_0.3.2.1.1 reshape_0.8.4       reshape2_1.2.2      RODBC_1.3-10 [31] sandwich_2.3-0      scales_0.2.3        seqinr_3.0-9        signal_0.7-3        splines_3.0.2 [36] stats4_3.0.2        stringr_0.6.2       survival_2.37-7     TH.data_1.0-3       tools_3.0.2 [41] vegan_2.1-41        watervogels_0.5-51  xtable_1.7-3        zoo_1.7-11


Best regards,

Thierry


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx@inbo.be<mailto:Thierry.Onkelinx@inbo.be>
www.inbo.be<http://www.inbo.be>

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey


* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.

______________________________________________
R-devel@r-project.org<mailto:R-devel@r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel




--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://joshuawiley.com/
Senior Analyst - Elkhart Group Ltd.
http://elkhartgroup.com
260.673.5518<tel:260.673.5518>
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.
______________________________________________
R-devel@r-project.org<mailto:R-devel@r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



--
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Mathematical Modelling, Statistics and Bio-Informatics

tel : +32 9 264 59 87
Joris.Meys@Ugent.be<mailto:Joris.Meys@Ugent.be>
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.

	[[alternative HTML version deleted]]

