SEXP dataframe_to_list(SEXP _source, SEXP _nrow, SEXP _ncol, SEXP _dest){
	Rcpp::DataFrame source = Rcpp::DataFrame(_source);
	Rcpp::GenericVector dest = Rcpp::GenericVector(_dest);
	int nrow = Rcpp::as<int>(_nrow);
	int ncol = Rcpp::as<int>(_ncol);	
	for (int j = 0; j < ncol; j ++){
		Rcpp::RObject robj = source[j];
		switch(robj.sexp_type()) {
			case RAWSXP: {
				Rcpp::RawVector z = source[j]; 
				for (int i = 0; i < nrow; i ++) {
					Rcpp::List l = dest[i];
					l[j] = Rcpp::wrap(z[i]);}}
			break;
			case STRSXP: {
				Rcpp::CharacterVector z = source[j]; 
				for (int i = 0; i < nrow; i ++) {
					Rcpp::List l = dest[i];
					l[j] = Rcpp::wrap(z[i]);}}
			break;
			case LGLSXP: {
				Rcpp::LogicalVector z = source[j]; 
				for (int i = 0; i < nrow; i ++) {
					Rcpp::List l = dest[i];
					l[j] = Rcpp::wrap(z[i]);}}
			break;
			case REALSXP: {
				Rcpp::NumericVector z = source[j]; 
				for (int i = 0; i < nrow; i ++) {
					Rcpp::List l = dest[i];
					l[j] = Rcpp::wrap(z[i]);}}
			break;
			case INTSXP: {
				Rcpp::IntegerVector z = source[j]; 
				for (int i = 0; i < nrow; i ++) {
					Rcpp::List l = dest[i];
					l[j] = Rcpp::wrap(z[i]);}}
			break;
			default: {
				throw UnsupportedType(robj.sexp_type());}}}
	return Rcpp::wrap(_dest);}
Exemple #2
0
Rcpp::IntegerVector process_subset_vector(Rcpp::RObject subset, int upper, bool zero_indexed) {
    if (subset.sexp_type()!=INTSXP) { 
        throw std::runtime_error("subset vector must be an integer vector");
    }  
    Rcpp::IntegerVector sout(subset);

    if (!zero_indexed) {
        sout=Rcpp::clone(sout);
        for (auto& s : sout) { --s; }
    }

    for (auto sIt=sout.begin(); sIt!=sout.end(); ++sIt) {
        if (*sIt < 0 || *sIt >= upper) { 
            throw std::runtime_error("subset indices out of range");
        }
    }
    return sout;
}