예제 #1
0
// 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;
}
예제 #2
0
파일: Redis.cpp 프로젝트: agstudy/rhiredis
    // 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);
    }