Write Rdata File From C ++

Suppose I have a C ++ program that has a vector of objects that I want to write to the data.frame Rdata file, one observation of the vector element. How can i do this? Here is an example. Let's pretend that

vector<Student> myStudents;

And Student- this is a class that has two data elements name, which has a type std::stringand gradewhich has a type int.

Is the only option to write a csv file?

Note that Rdata is a binary format, so I think I will need to use a library.

The search for Rdata [r] [C ++] turned out to be empty.

+5
source share
2 answers

, R, R.

Octave, : "n" "k", "n * k" - / .

, R R, (?) , R, Rserve ( " " tcp/ip) RInside ( ), R .

+4

, (, ), :

using namespace std;
using namespace Rcpp;
using Eigen::Map; 
using Eigen::MatrixXi;
using Eigen::MatrixXd;

Environment base("package:base");

Function save = base["save"];
Function saveRDS = base["saveRDS"];

MatrixXd M = MatrixXd::Identity(3,3);

NumericMatrix xx(wrap(M));
NumericMatrix xx1(wrap(M));
NumericMatrix xx2(wrap(M));

base["xx"] = xx;
base["xx1"] = xx1;
base["xx2"] = xx2;

vector<string> lst;
lst.push_back("xx");
lst.push_back("xx1");
lst.push_back("xx2");
CharacterVector all = wrap(lst);

save(Named("list", all), Named("envir", base) , Named("file","Identities.RData"));
saveRDS(xx,Named("file","Identity.RDs"));
return wrap(M);
library(inline)
library(Rcpp)
library(RcppEigen)

src <- '
#put here cpp code shown above 
'

saveworkspace <- cxxfunction(signature(), src, plugin = "RcppEigen")
saveworkspace()
list.files(pattern="*.RD*")


[1] "Identity.RDs"
[2] "Identities.RData"

100%, ++ / .

NB. , R, , , R, .

0

All Articles