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

Rcpp error when using prophet::prophet() instead of library(prophet) #285

Open
z1lc opened this issue Aug 31, 2017 · 7 comments
Open

Rcpp error when using prophet::prophet() instead of library(prophet) #285

z1lc opened this issue Aug 31, 2017 · 7 comments

Comments

@z1lc
Copy link

z1lc commented Aug 31, 2017

When I don't use library(prophet) and instead use the fully-qualified prophet::prophet, I get the following in my console:

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)
prophet::prophet(data.frame(ds = ds, y = y), yearly.seasonality = FALSE)

Error in .Object$initialize(...) :
could not find function "cpp_object_initializer"
failed to create the optimizer; optimization not done
Error in matrix(m$params[[name]], nrow = n.iteration) :
'data' must be of a vector type, was 'NULL'

I'm using the latest revision from master (via devtools::install_github('facebookincubator/prophet', subdir='R'))

@z1lc z1lc mentioned this issue Aug 31, 2017
@bletham
Copy link
Contributor

bletham commented Sep 12, 2017

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.

@bgoodri
Copy link

bgoodri commented Sep 29, 2017

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.

@megan-stamper
Copy link

Any updates on this? Having the same issue while writing a package using prophet's functions.

@bletham
Copy link
Contributor

bletham commented Dec 20, 2018

@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.

@bgoodri
Copy link

bgoodri commented Dec 20, 2018

If you have Rcpp in Depends, then I think it should work.

@bletham
Copy link
Contributor

bletham commented Jan 5, 2019

@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 RcppCore/Rcpp#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?

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

No branches or pull requests

5 participants