|
|
Thinking inside the box | |||||
|
Bio
Code Papers Talks Linux Quantian About Blog
|
New package RcppCNPy with release 0.1.0 (and 0.0.1 earlier last week)
Bringing such a C++ library to R is done very easily via Rcpp modules.
The resulting package contains a single R file with a single line:
which give us at the R promptRCPP_MODULE(cnpy){ using namespace Rcpp; function("npyLoad", // name of the identifier at the R level &npyLoad, // function pointer to helper function defined above List::create( Named("filename"), // function arguments including default value Named("type") = "numeric"), "read an npy file into a numeric or integer vector or matrix"); function("npySave", // name of the identifier at the R level &npySave, // function pointer to helper function defined above List::create( Named("filename"), // function arguments including default value Named("object"), Named("mode") = "w"), "save an R object (vector or matrix of type integer or numeric) to an npy file"); } these two functions (and their docstrings) defined above. That's all! Well there are about one hundred more lines dealing with whether we have integer or numeric data, and whether we use a vector or a matrix. But all in all pretty simple...R> library(RcppCNPy) Loading required package: Rcpp R> npyLoad internal C++ function <0x243af70> docstring : read an npy file into a numeric or integer vector or matrix signature : Rcpp::RObject npyLoad(std::string, std::string) R> npySave internal C++ function <0x23033e0> docstring : save an R object (vector or matrix of type integer or numeric) to an npy file signature : void npySave(std::string, Rcpp::RObject, std::string) R> So version 0.1.0 of this new package RcppCNPy completes the initial release 0.0.1 from earlier in the week by adding
The NEWS entry for this release (as well as the initial one) follow: I will follow up with a little usage example later. CRANberries also provides a diffstat report for 0.1.0 relative to 0.0.1. As always, feedback is welcome and the rcpp-devel mailing list off the R-Forge page for Rcpp is the best place to start a discussion. |
|||||