0

I am using a truely wonderfull package Rcpp to pass my C++ function dataset(name) which generates synthetic datasets to R. One of the datasets constant_file is not generated/sampled, but is contained in an .Rdata file. Is it possible to return it when passed to the function dataset under name dataset(constant_file)? I googled it, but it did not seem like an option.

The function dataset seems something like this:

Eigen::MatrixXd generate_dataset(std::string name) {
if (name == "box") {
... generate a uniform sample from box and return it...
} 
if (name == "constant_file") {
... read the .Rdata or .csv and return it ...
}
}
qarabala
  • 178
  • 10
  • 4
    Hi Cebis. It's not really clear what you are asking. Do you want your C++ function to be able to read a `.RData` file and return it to R? You are unlikely to get a helpful response here unless you provide a bit more information, including the code for your `dataset` function. You may be able to use [this library](https://github.com/WizardMac/librdata) if your function is part of a package. – Allan Cameron Aug 13 '20 at 15:25
  • 3
    You know how to do it in R, so I would just do it in R. If you want to be complicated, you can call an R function from C++ via Rcpp, but I would probably try to convince myself that it is worth it... – Dirk Eddelbuettel Aug 13 '20 at 15:29
  • 4
    @AllanCameron Yup! And extra bonus points for Evan's library which helps _if one does not have R around_ but given Rcpp use there is R so preferable to just read the file with R. – Dirk Eddelbuettel Aug 13 '20 at 15:30
  • 1
    Now that I think about it, doing it in R (not exported) and then calling an R function from the desired C++ function seems like a clever way to go! Shame one cannot accept a comment as an answer... – qarabala Aug 13 '20 at 18:34

0 Answers0