stan-dev / stan-dev/rstanarm

`stan_lmer` cannot be used through namespacing (`rstanarm::stan_lmer`)

Open
#589 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
401
Forks
136
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the namespaced stan_lmer call and the resulting stan_glmer lookup failure. Trace how stan_lmer resolves stan_glmer when rstanarm is accessed through its namespace, then inspect the package's existing tests or function definitions. Done means namespaced use works without requiring the package to be attached or relying on super-assignment.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.