Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lmer. Error in deparse1(x[[3]]): could not find function "deparse1" when running multilevel models #649

Closed
YiyangGao opened this issue Nov 24, 2021 · 8 comments

Comments

@YiyangGao
Copy link

Hi there, I am running multilevel models with lme4. When I fit the null model,
nullmodel <- lmer(mathscore ~ (1| schoolid), data = census)

I received an error message saying "Error` in deparse1(x[[3]]): could not find function "deparse1"".

Google says I may need to update the package backports. But I still receive the error message even with the package updated. May I please know what is the problem here?

Many thanks for your help.

@bbolker
Copy link
Member

bbolker commented Nov 24, 2021

Please don't cross-post here and on Stack Overflow. This error is surprising; although deparse1 was not defined until R version 4.0.0, we have code that's supposed to add a backward compatibility layer. Can you (1) confirm that you get the same error with a reproducible/built-in example (e.g. nullmodel <- lmer(Reaction ~ (1|Subject), data = sleepstudy)) and (2) post the results of sessionInfo() from a clean R session?

PS I wonder if we need to conditionally export deparse1, because some evaluation is happening in a parent frame that can't see the version of deparse1 in the package namespace ...??

@YiyangGao
Copy link
Author

Thank you so much for your prompt reply, Ben. I have closed the enquiry on Stack Overflow. Do apologise for the confusion. I have tried to run the null model with the built-in example. Unfortunately, it returns with the same error message. As for the sessionInfo(), I am running the model in a safe setting without Internet connection, thus I cannot copy and paste the results. But here is the first three lines of the results:
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2012 R2 x64 (build 9600)

As you said, deparse1 was not defined until R version 4.0.0. Due to the issue of loading correct file paths, I have to use R version 3.6.1, instead of R 4.0.0. I was wondering if this could be the reason that I encountered this error. Would it be possible to solve this problem by installing an early version of lme4? I am now using lme4_1.1-27.1.

Do apologise for the confusion. And many thanks for your help.

@bbolker
Copy link
Member

bbolker commented Nov 24, 2021

Well, it ought to work with R 3.6.1. It's just a nuisance to find a platform for debugging it. Maybe I'll finally figure out how to use rocker: https://hub.docker.com/r/rocker/r-ver

I have docker installed already, so according to this:

docker run --rm -ti rocker/r-ver:3.6.1

Seems to be working so far but haven't gotten up to an actual test yet ...

@mmaechler
Copy link
Member

I've been surprised too by this problem. I think I know what's going on: @YiyangGao uses WIndows and hence will have got a binary installed package lme4 which was "built" using R 4.0.x or even R 4.1.x AND for binary builds, the check for the R version happens at install time and the need for old compatibility wrappers is determined at that time... when a more modern version of R is in use. I recommend Yiyang Gao install the 'Rtools' for Windows (but you need the old "tools36" !) and then install the package from the source instead of binary:

install.packages("lme4", type="source")

For us (as lme4 maintainers) to solve this correctly in this age (where so much happens at install time) we'd need a more ugly solution, putting all those compatibility definitions inside .onLoad() .. the uglyness being that loading lme4 becomes slightly slower on all platforms just to help the really old platforms.
.... OTOH, "slightly slower" may well be in the order of milli seconds, and so I think we can afford it.

@YiyangGao
Copy link
Author

Thank you both for your great support @bbolker @mmaechler Really appreciate it. I have just found the old version of lme4, lme4_1.1-21, is available in the safe data setting. This old version of lme4 works, but everytime when I use lme4_1.1-27.1, it will return with the error message. It seems that this error is something to do with the incompatibility between the new version of lme4 and R 3.6.1. So far it seems to work well. I will run the rest of my code to see if I could complete the multilevel models.

I do apologse for the confusion. And many many thanks for your support. Do appreciate.

@bbolker
Copy link
Member

bbolker commented Nov 25, 2021

@mmaechler , am I correct in thinking that our assignments of functions inside .onLoad() have to look like this?

 assign('...names', envir = topenv(),
           function() eval(quote(names(list(...))), sys.frame(-1L)))

(the accepted answer in this SO question uses envir = parent.env(environment()), but Konrad Rudolph's uses envir = topenv() which seems slightly more compact ...

@mmaechler
Copy link
Member

mmaechler commented Nov 25, 2021

Well, I'm guessing (haven't tried) that even more compactly, you'd be able to use <<- which I'd prefer if it worked here... but yes, I was aware that the assignments would have to happen with care.
Also, BTW, I'm not 100% sure if topenv() and parent.env(environment()) would always be equivalent;
If <<- does not work, I'd consider something like an initial

myNs <- asNamespace("lme4")

or actually, if you have pkgname as typically inside .onLoad <- function(pkgname, ...) { ...... },
I'd use

myNs <- asNamespace(pkgname)

which would make the code a " generic role model " more generally.

and then for each object (here, function) to use envir = myNS

@bbolker
Copy link
Member

bbolker commented Jan 24, 2022

fixed in cf4bdcb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants