Giter Site home page Giter Site logo

Comments (12)

jsilve24 avatar jsilve24 commented on May 28, 2024 2

This is a problem that should probably be fixed. Putting code in generated quantities block is very limiting.

from rstantools.

jtipton25 avatar jtipton25 commented on May 28, 2024

I'm having the same issue but deleting this block of code doesn't fix it. I used rstanstools::rstan_package_skeleton to setup a package and added the default timesTwo.cpp to the package. I'm getting the error

Error in timesTwo(rnorm(10)) : object '_test_timesTwo' not found

I'd like to have a package to fit a model using RStan and then use an RcppArmadillo function to post-process the data. I can't find any documentation referring to implementing stand-alone Rcpp functions within an RStan package. Any help would be appreciated.

from rstantools.

bgoodri avatar bgoodri commented on May 28, 2024

from rstantools.

lucasnell avatar lucasnell commented on May 28, 2024

I agree with above. I'm trying to make a package that includes simulations using Rcpp, and having those functions in generated quantities blocks instead of their own .cpp files is a real problem.

from rstantools.

jtimonen avatar jtimonen commented on May 28, 2024

I would also need RcppArmadillo to work in a package created using Rstantools. I have the same problem: object [name of function] not found

from rstantools.

helske avatar helske commented on May 28, 2024

I have successfully combined external C++ and Stan models in the same package in the past (https://github.com/helske/walker), but I just started to update some stuff and something has changed so that I new I get an infinite recompilation loops... And if I switch to newer package skeleton structure, I also face the issue that either Stan models or other C++ functions are not getting exported (depending on how I tweak Makevars etc).

from rstantools.

bgoodri avatar bgoodri commented on May 28, 2024

from rstantools.

helske avatar helske commented on May 28, 2024

Yes I just realized that as well, removing the roxygen line fixed the infinite loop issue and the package compiles. But the Stan models are not getting exported. Investigation continues...

edit: Oops, I had a wrong version of the stanmodels.R file. Everything works now: https://github.com/helske/walker.

from rstantools.

bgoodri avatar bgoodri commented on May 28, 2024

from rstantools.

const-ae avatar const-ae commented on May 28, 2024

I encountered the same problem today, that I couldn't use Rcpp functions in a package generated with rstanstools::rstan_package_skeleton.

I found that removing the R_init_mypackage function fixes the problem of calling the Rcpp functions, because the function is then generated by Rcpp in RcppExports.cpp. But I got another error when I loaded the package that "object 'm' not found" as described in issue #43.

I solved this issue by adding

// [[Rcpp::init]]
void rstan_additional_init(DllInfo *dll){
  R_useDynamicSymbols(dll, TRUE); // necessary for .onLoad() to work
}

which makes sure that the dynamic symbol is accessible in the .onLoad function in zzz.R.

So in conclusion, replacing the R_init_mypackage function with the code above fixed my problem.

from rstantools.

bgoodri avatar bgoodri commented on May 28, 2024

from rstantools.

bart1 avatar bart1 commented on May 28, 2024

Just a quick comment to add to @const-ae, encountered the same issue and had some trouble getting it to work, in addition to @const-ae suggestion that were required. A few quick notes that would have helped me. You also need to include RcppExports.o and the other Rcpp source files in the sources variable of Makevars (and I assume Makevars.win but have not tested that)
I was also having troubles with including RcppArmadillo, it turns out I needed to import it before importing RcppEigen in the DESCRIPTION file.

from rstantools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.