// the serialization function from SEXP to std::string inline std::string serializeToStr(SEXP object) { // using R's C API, all SEXP objects will be serialized into a raw vector Rcpp::RawVector val = serializeToRaw(object); // convert R raw vector into a std::string std::string res; for (size_t i = 0; i < val.size(); i++) { res = res + std::to_string(int(val[i])) + "\t"; } return res; }
// redis set -- serializes to R internal format std::string set(std::string key, SEXP s) { // if raw, use as is else serialize to raw Rcpp::RawVector x = (TYPEOF(s) == RAWSXP) ? s : serializeToRaw(s); // uses binary protocol, see hiredis doc at github redisReply *reply = static_cast<redisReply*>(redisCommand(prc_, "SET %s %b", key.c_str(), x.begin(), x.size())); std::string res(reply->str); freeReplyObject(reply); return(res); }