[R-pkg-devel] help with CRAN failures (broom.mixed, rstan-related)
Ivan Krylov
|kry|ov @end|ng |rom d|@root@org
Wed Sep 25 22:22:43 CEST 2024
В Wed, 25 Sep 2024 12:28:25 -0400
Ben Bolker <bbolker using gmail.com> пишет:
> What is your current estimate of the probability that this is
> something that I've done wrong vs. exposing something wonky elsewhere
> (i.e. at the level of testthat, brms, rstan, Rcpp, R-devel, ...) ?
I didn't have a good answer (the most recently updated package should
be the one to suspect, right?), but stopping the investigation now
would be akin to closing a murder mystery in the middle of the last
chapter. Here's what I've been able to find out:
When running library(testthat); debugonce(Rcpp::loadModule);
source('tests/testthat/test-alltibbles.R'), by the time we reach
Rcpp:::loadModule, the reference classes don't come out right. A simple
new('C++OverloadedMethods') returns an object that doesn't have a $show
or $info method. A similar problem happens for 'envRefClass', from
which 'C++OverloadedMethods' inherits: printing it will fail due to a
missing $show() method.
The problem is not in the class definition or object contents. I don't
see differences between serialised class definitions. Reloading a
serialized object from a "broken" R session into a fresh R session makes
it work normally.
The first difference I was able to notice was in how the $ operator
works for the reference semantics objects. In both cases,
.Primitive('$') -> do_subset3 eventually calls DispatchOrEval(). In a
healthy R session, the test [*] for IS_S4_OBJECT(x) &&
R_has_methods(op) succeeds. In a "broken" R session it fails because
R_has_methods(op) is FALSE.
That's because allowPrimitiveMethods had been set to FALSE.
Judging by the traceback, brms::variables(object) ->
variables.brmsfit(object) -> dimnames(x$fit) needs to resolve the S4
'dimnames' method for class 'stanfit'. At this point
methods:::.findInheritedMethods temporarily disables S4 methods for
primitives. The comment says it's done "to avoid infinite recursion,
and somewhat for speed". Unfortunately, later the 'rstan' namespace
needs to be loaded, and 'rstan' calls Rcpp functions that use reference
classes, which break without S4 dispatch for `$`.
As far as endings go, this one is rather like Murder on the Orient
Express. Even understanding what happened doesn't point towards the
"right" fix. Josiah's suggestion should have helped by loading the
namespace at a safer time.
--
Best regards,
Ivan
[*]
https://github.com/r-devel/r-svn/blob/776045d4601ed3ac7b8041e94c665bbfe9709191/src/main/eval.c#L4152
More information about the R-package-devel
mailing list