qsbase / qs

Quick serialization of R objects
400 stars 19 forks source link

Expose C++ API to use in other Rcpp packages #18

Closed artemklevtsov closed 5 years ago

artemklevtsov commented 5 years ago

Hi, Thank you for the excellent package. It would to use C++ function in other packages which use Rcpp.

traversc commented 5 years ago

I'll look into it! Not sure how hard it will be.

artemklevtsov commented 5 years ago

Thank you. As start point I suggest this doc (section 3.6): http://dirk.eddelbuettel.com/code/rcpp/Rcpp-attributes.pdf

traversc commented 5 years ago

Thanks for the link, and pointing to the correct section!

Would you mind testing it out on the latest github version? Here is an example.

// [[Rcpp::depends(qs)]]
#include <Rcpp.h>
#include <qs.h>
using namespace Rcpp;

// [[Rcpp::export]]
void test() {
  qs::c_qsave(IntegerVector::create(1,2,3), "/tmp/myfile.qs", "high", "zstd", 1, 15, true, 1);
}

/*** R
library(qs)
# save file using Rcpp interface
test()
# read in file create through Rcpp interface
qread("/tmp/myfile.qs")
*/
artemklevtsov commented 5 years ago

Thank you for the quick reply. Now it's work. I tried example with c_qserialize.

traversc commented 5 years ago

I uploaded a new version to CRAN with C++ API: https://cran.r-project.org/web/packages/qs/index.html. Closing this now :)

artemklevtsov commented 5 years ago

Thank you.