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

stan_lmer cannot be used through namespacing (rstanarm::stan_lmer) #589

Open
rempsyc opened this issue May 7, 2023 · 1 comment
Open

Comments

@rempsyc
Copy link

rempsyc commented May 7, 2023

Summary:

stan_lmer cannot be used through namespacing (rstanarm::stan_lmer), which creates issues in packages depending on rstanarm.

Description:

stan_lmer cannot be used through namespacing (rstanarm::stan_lmer), because it generates an error, could not find function "stan_glmer". This creates issues in packages depending on rstanarm, such as the report package.

A workaround that we have been using is super-assignment, of the following type:

stan_glmer <<- rstanarm::stan_glmer

However, for mysterious reasons, during our automated tests, even though we never explicitly load the rstanarm library, sometimes it will load itself. Once loaded, it will not allow super-assignment to overwrite its function name, with error cannot change value of locked binding for 'stan_glmer'. This can be reproduced with the steps below:

Reproducible Steps:

R.Version()$version.string
#> [1] "R version 4.3.0 (2023-04-21 ucrt)"
R.Version()$platform
#> [1] "x86_64-w64-mingw32"
packageVersion("rstanarm")
#> [1] '2.21.4'

x <- rstanarm::stan_lmer(Sepal.Length ~ Petal.Length + (1 | Species),
                         data = iris, refresh = 0, iter = 1000, seed = 333)
#> Error in stan_glmer(formula = Sepal.Length ~ Petal.Length + (1 | Species), : could not find function "stan_glmer"

suppressPackageStartupMessages(library(rstanarm))

stan_glmer <<- rstanarm::stan_glmer
#> Error in eval(expr, envir, enclos): cannot change value of locked binding for 'stan_glmer'

Created on 2023-05-07 with reprex v2.0.2

Question

Is there any official workaround for this issue?

@rempsyc
Copy link
Author

rempsyc commented May 7, 2023

This can be reproduced with R version 4.2.2 on Windows locally and on automated tests on GitHub actions machines.

R.Version()$version.string
#> [1] "R version 4.2.2 (2022-10-31 ucrt)"
R.Version()$platform
#> [1] "x86_64-w64-mingw32"
packageVersion("rstanarm")
#> [1] '2.21.3'

x <- rstanarm::stan_lmer(Sepal.Length ~ Petal.Length + (1 | Species),
                         data = iris, refresh = 0, iter = 1000, seed = 333)
#> Error in stan_glmer(formula = Sepal.Length ~ Petal.Length + (1 | Species), : could not find function "stan_glmer"

suppressPackageStartupMessages(library(rstanarm))

stan_glmer <<- rstanarm::stan_glmer
#> Error in eval(expr, envir, enclos): cannot change value of locked binding for 'stan_glmer'

Created on 2023-05-07 with reprex v2.0.2

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

1 participant