[Rcpp-devel] check validity of object created from Rcpp module
Dirk Eddelbuettel
edd at debian.org
Wed Jun 27 02:04:57 CEST 2012
On 26 June 2012 at 17:21, Jiqiang Guo wrote:
| Dear List,
|
| I am wondering if there is a way to check whether an object created from Rcpp's
| module is valid or not especially for objects loaded in another session.
|
| In detail, we know that we could not save and load objects created from Rcpp's
| module [section 5 of http://cran.r-project.org/web/packages/Rcpp/vignettes/
| Rcpp-modules.pdf]. But that does not prevent users doing that. So if an
| object created from Rcpp's module is loaded in another session, we would end up
| with errors or even segfault. It would be nice we have a method to check if
| it is valid or not so that when we are writing a package, we could do a check
| before calling those methods of that object.
It's a very good idea. I don't have a good idea as to how we'd do this though.
Dirk
| An illustrative example:
|
| require("Rcpp")
| require("inline")
|
| inc <- '
| class Foo {
| private:
| int x_;
| public:
| Foo(int x) : x_(x) { }
| int getx() const { return x_;}
| };
|
| RCPP_MODULE(foo) {
| class_<Foo>("Foo")
| .constructor<int>()
| .method("getx", &Foo::getx)
| ;
| }
|
| fx <- cxxfunction(signature(), "", include = inc, plugin = "Rcpp", verbose =
| FALSE)
| m <- Module("foo", getDynLib(fx))
| cppo = new(m$Foo, 5)
|
| print(cppo$getx())
| save("cppo", file = 'cppo.RData')
|
| rm(list = ls())
| load("cppo.RData")
| print(cppo$getx())
|
| For the above code, we know the last line would not work. If we have a
| function to test the validity of cppo,then if not valid, we would not call
| cppo's function and are able to tell users that cppo is not valid any more.
|
| Best,
| Jiqiang
|
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list