Skip to content
Prev 2719 / 10988 Next

[Rcpp-devel] Hello world for Rcpp modules

Got it now:  you cannot just drop code in an R file, that has nothing to do
with Rcpp methinks.   Wrap it in a function like so:

edd at max:/tmp$ R CMD INSTALL chrisExample/
* installing to library ?/usr/local/lib/R/site-library?
* installing *source* package ?chrisExample? ...
** libs
make: Nothing to be done for `all'.
installing to /usr/local/lib/R/site-library/chrisExample/libs
** R
** preparing package for lazy loading
** help
Warning: /tmp/chrisExample/man/chrisExample-package.Rd:32: All text must be in a section
Warning: /tmp/chrisExample/man/chrisExample-package.Rd:33: All text must be in a section
*** installing help indices
** building package indices ...
** testing if installed package can be loaded

* DONE (chrisExample)
edd at max:/tmp$ r -lchrisExample  -e'chris()'
C++ class 'World' <0x2a55d60>
Constructors:
    World()

Fields: No public fields exposed by this class

Methods: 
     std::string greet()  
           docstring : get the message
     void set(std::string)  
           docstring : set the message
edd at max:/tmp$ cat chrisExample/R/rcpp_hello_world2.R 

chris <- function() {
    show(World)
    b <- new(World)
    b$greet()
    b$set("hello everybody")
    b$greet()
    rm(b)

    invisible(NULL)
}
edd at max:/tmp$ 

Ok?

Dirk