Open z1lc opened 7 years ago
From searching for this issue it seems to be related to Rcpp, but we have already done the thing that I could find as a solution (include Rcpp in the Depends). We should see how rstanarm does this.
@z1lc @bletham
is this the root cause?
Even rstan::sampling
throws the same error if you don't do library(rstan)
first. The only known way to get foo::bar
to work when bar
is calling Stan is for foo to depend (not import from) Rcpp so that Rcpp gets loaded before the Module magic happens.
Any updates on this? Having the same issue while writing a package using prophet's functions.
@megan-stamper I haven't looked into this any further. @bgoodri would certainly know, though we do have Rcpp in the Depends so there must be something else going on. I think looking at other packages that call Stan might reveal if there is something that can be done to resolve this.
If you have Rcpp in Depends, then I think it should work.
@bgoodri We have Rcpp in depends:
Depends: R (>= 3.2.3), Rcpp (>= 0.12.0), rlang (>= 0.3.0.1)
Imports: dplyr (>= 0.5.0), dygraphs (>= 1.1.1.4), extraDistr, ggplot2,
grid, rstan (>= 2.14.0), scales, stats, tidyr (>= 0.6.1), xts
Suggests: knitr, testthat, readr
NAMESPACE has these imports:
import(Rcpp)
import(rlang)
importFrom(dplyr,"%>%")
But still get the error when we call rstan::optimizing
internally in the package:
> ds <- seq(as.Date('2005-04-01'), as.Date('2005-09-03'), by='day')
> x <- (1:length(ds))/length(ds)
> y <- rnorm(length(ds), x * (1 - x) + 0.5, 0.1)
> m <- prophet::prophet(data.frame(ds = ds, y = y), yearly.seasonality=FALSE, daily.seasonality=FALSE)
Error in .Object$initialize(...) :
could not find function "cpp_object_initializer"
failed to create the optimizer; optimization not done
Based on your comment in https://discourse.mc-stan.org/t/strange-new-error-when-running-code-that-has-always-worked-before/6846/2 I replaced rstan::optimizing
with an importFrom(rstan, optimizing)
in the NAMESPACE and directly calling optimizing
in the package, but we still get the error.
Based on the comments in https://github.com/RcppCore/Rcpp/issues/168 I also tried adding importFrom(Rcpp, cpp_object_initializer)
to the NAMESPACE but that didn't do anything.
Do you have any suggestions on further directions to look?
When I don't use
library(prophet)
and instead use the fully-qualifiedprophet::prophet
, I get the following in my console:I'm using the latest revision from master (via
devtools::install_github('facebookincubator/prophet', subdir='R')
)