DenseMatrix RMAExpressMatrixReader::read(std::istream& input, unsigned int opts) const { //TODO: interpret the passed options if(readString_(input) != "RMAExpressionValues") { return DenseMatrix(0,0); } uint32_t version; input.read(reinterpret_cast<char*>(&version), 4); if(version != 1) { return DenseMatrix(0,0); } skipString_(input); // Skip the RMAExpress version number skipString_(input); // Skip the chiptype uint32_t nrows, ncols; input.read(reinterpret_cast<char*>(&ncols), 4); input.read(reinterpret_cast<char*>(&nrows), 4); std::vector<std::string> colnames(ncols); std::vector<std::string> rownames(nrows); readStringVector_(input, colnames); readStringVector_(input, rownames); DenseMatrix result(std::move(rownames), std::move(colnames)); input.read(reinterpret_cast<char*>(result.matrix().data()), nrows * ncols * sizeof(double)); return result; }
List maxmind_bindings::call_maxmind(std::vector < std::string > ip_addresses, const char* file, std::vector < std::string > fields){ //Open file MMDB_s geo_file; int result; result = MMDB_open(file, 0, &geo_file); if(result != MMDB_SUCCESS){ throw std::range_error("The geolocation database could not be opened"); } //Create references and holding std::vector < std::string >& ip_ref = ip_addresses; int input_size = ip_addresses.size(); IntegerVector rownames(input_size); rownames = Rcpp::seq(1,input_size); List output = lookup(ip_ref, &geo_file, fields); output.attr("class") = "data.frame"; output.attr("names") = fields; output.attr("row.names") = rownames; //Close and return MMDB_close(&geo_file); return output; }
SEXP rawSymmetricMatrixSubsetIndices(SEXP object_, SEXP i_, SEXP j_, SEXP drop_) { BEGIN_RCPP Rcpp::S4 object = object_; Rcpp::CharacterVector markers = object.slot("markers"); Rcpp::NumericVector levels = object.slot("levels"); Rcpp::RawVector data = object.slot("data"); Rcpp::IntegerVector i = i_; Rcpp::IntegerVector j = j_; bool drop = Rcpp::as<bool>(drop_); if(drop) { if(i.size() == 1 && j.size() == 1) { R_xlen_t i = Rcpp::as<int>(i_); R_xlen_t j = Rcpp::as<int>(j_); if(i > j) std::swap(i, j); Rbyte rawValue = data[(j*(j-(R_xlen_t)1))/(R_xlen_t)2 + i-(R_xlen_t)1]; if(rawValue == 0xff) return Rcpp::wrap(NA_REAL); return Rcpp::wrap(levels[rawValue]); } else if(i.size() == 1) { Rcpp::NumericVector result(j.size()); R_xlen_t i = Rcpp::as<int>(i_); Rcpp::CharacterVector names(j.size()); for(R_xlen_t jCounter = 0; jCounter < j.size(); jCounter++) { R_xlen_t iCopied = i; R_xlen_t jValue = j[jCounter]; names[jCounter] = markers[jValue-(R_xlen_t)1]; if(iCopied > jValue) std::swap(iCopied, jValue); Rbyte rawValue = data[(jValue*(jValue-(R_xlen_t)1))/(R_xlen_t)2 + iCopied-(R_xlen_t)1]; if(rawValue == 0xff) result[jCounter] = NA_REAL; else result[jCounter] = levels[rawValue]; } result.attr("names") = names; return result; } else if(j.size() == 1) { Rcpp::NumericVector result(i.size()); R_xlen_t j = Rcpp::as<int>(j_); Rcpp::CharacterVector names(i.size()); for(R_xlen_t iCounter = 0; iCounter < i.size(); iCounter++) { R_xlen_t jCopied = j; R_xlen_t iValue = i[iCounter]; names[iCounter] = markers[iValue-(R_xlen_t)1]; if(iValue > jCopied) std::swap(iValue, jCopied); Rbyte rawValue = data[(jCopied*(jCopied-(R_xlen_t)1))/(R_xlen_t)2 + iValue-(R_xlen_t)1]; if(rawValue == 0xff) result[iCounter] = NA_REAL; else result[iCounter] = levels[rawValue]; } result.attr("names") = names; return result; } } Rcpp::NumericMatrix result((int)i.size(), (int)j.size()); Rcpp::CharacterVector rownames(i.size()), colnames(j.size()); for(R_xlen_t iCounter = 0; iCounter < i.size(); iCounter++) { rownames[iCounter] = markers[i[iCounter]-(R_xlen_t)1]; for(R_xlen_t jCounter = 0; jCounter < j.size(); jCounter++) { R_xlen_t iCopied = i[iCounter], jCopied = j[jCounter]; if(iCopied > jCopied) std::swap(iCopied, jCopied); Rbyte rawValue = data[(jCopied*(jCopied-(R_xlen_t)1))/(R_xlen_t)2 + iCopied-(R_xlen_t)1]; if(rawValue == 0xff) result(iCounter, jCounter) = NA_REAL; else result(iCounter, jCounter) = levels[rawValue]; } } for(R_xlen_t jCounter = 0; jCounter < j.size(); jCounter++) { colnames[jCounter] = markers[j[jCounter]-(R_xlen_t)1]; } result.attr("dimnames") = Rcpp::List::create(rownames, colnames); return result; END_RCPP }