SEXP data_frame_from_apop_data(apop_data *in){ if (!in) return R_NilValue; int numeric_rows = !!(in->vector) + (in->matrix ? in->matrix->size2 : 0) + !!(in->weights); int text_rows = in->textsize[1]; SEXP out, onerow; PROTECT(out = allocVector(VECSXP, numeric_rows + text_rows)); int col_ct = 0; int firstcol = in->vector ? -1 : 0; int lastcol = in->matrix ? in->matrix->size2 : 0; for (int i= firstcol; i < lastcol; i++){ int len = (i == -1) ? in->vector->size : in->matrix->size1; apop_data *factorpage = find_factor(onerow, in, i); if (factorpage){ SET_VECTOR_ELT(out, col_ct++, (onerow = allocVector(INTSXP, len))); for (int j=0; j< len; j++) INTEGER(onerow)[j] = apop_data_get(in, j, i); set_factor(onerow, factorpage); } else { SET_VECTOR_ELT(out, col_ct++, (onerow = allocVector(REALSXP, len))); for (int j=0; j< len; j++) REAL(onerow)[j] = apop_data_get(in, j, i); } } for (int i= 0; i < text_rows; i++){ int len = in->textsize[0]; SEXP onerow; SET_VECTOR_ELT(out, col_ct++, (onerow = allocVector(STRSXP, len))); for (int j=0; j< len; j++) SET_STRING_ELT(onerow, j, mkChar(in->text[j][i])); //Do I need strdup? } if (in->weights){ int len = in->weights->size; SET_VECTOR_ELT(out, col_ct++, (onerow = allocVector(REALSXP, len))); for (int j=0; j< len; j++) REAL(onerow)[j] = gsl_vector_get(in->weights, j); } handle_names(in, out); UNPROTECT(1); return out; }
bool ContextIntersect::parseCmdArgs(int argc, char **argv, int skipFirstArgs) { _argc = argc; _argv = argv; _skipFirstArgs = skipFirstArgs; if (_argc < 2) { setShowHelp(true); return false; } setProgram(_programNames[argv[0]]); _argsProcessed.resize(_argc - _skipFirstArgs, false); for (_i=_skipFirstArgs; _i < argc; _i++) { if (isUsed(_i - _skipFirstArgs)) { continue; } if (strcmp(_argv[_i], "-a") == 0) { if (!handle_a()) return false; } else if (strcmp(_argv[_i], "-abam") == 0) { if (!handle_abam()) return false; } else if (strcmp(_argv[_i], "-b") == 0) { if (!handle_b()) return false; } else if (strcmp(_argv[_i], "-names") == 0) { if (!handle_names()) return false; } else if (strcmp(_argv[_i], "-filenames") == 0) { if (!handle_filenames()) return false; } else if (strcmp(_argv[_i], "-u") == 0) { if (!handle_u()) return false; } else if (strcmp(_argv[_i], "-f") == 0) { if (!handle_f()) return false; } else if (strcmp(_argv[_i], "-wa") == 0) { if (!handle_wa()) return false; } else if (strcmp(_argv[_i], "-wao") == 0) { if (!handle_wao()) return false; } else if (strcmp(_argv[_i], "-wb") == 0) { if (!handle_wb()) return false; } else if (strcmp(_argv[_i], "-wo") == 0) { if (!handle_wo()) return false; } else if (strcmp(_argv[_i], "-c") == 0) { if (!handle_c()) return false; } else if(strcmp(_argv[_i], "-r") == 0) { if (!handle_r()) return false; } else if (strcmp(_argv[_i], "-v") == 0) { if (!handle_v()) return false; } else if (strcmp(_argv[_i], "-s") == 0) { if (!handle_s()) return false; } else if (strcmp(_argv[_i], "-S") == 0) { if (!handle_S()) return false; } else if (strcmp(_argv[_i], "-loj") == 0) { if (!handle_loj()) return false; } } return ContextBase::parseCmdArgs(argc, argv, _skipFirstArgs); }
bool ContextIntersect::parseCmdArgs(int argc, char **argv, int skipFirstArgs) { for (_i=_skipFirstArgs; _i < argc; _i++) { if (isUsed(_i - _skipFirstArgs)) { continue; } if (strcmp(_argv[_i], "-a") == 0) { if (!handle_a()) return false; } else if (strcmp(_argv[_i], "-abam") == 0) { if (!handle_abam()) return false; } else if (strcmp(_argv[_i], "-b") == 0) { if (!handle_b()) return false; } else if (strcmp(_argv[_i], "-names") == 0) { if (!handle_names()) return false; } else if (strcmp(_argv[_i], "-filenames") == 0) { if (!handle_filenames()) return false; } else if (strcmp(_argv[_i], "-u") == 0) { if (!handle_u()) return false; } else if (strcmp(_argv[_i], "-f") == 0) { if (!handle_f()) return false; } else if (strcmp(_argv[_i], "-F") == 0) { if (!handle_F()) return false; } else if (strcmp(_argv[_i], "-wa") == 0) { if (!handle_wa()) return false; } else if (strcmp(_argv[_i], "-wao") == 0) { if (!handle_wao()) return false; } else if (strcmp(_argv[_i], "-wb") == 0) { if (!handle_wb()) return false; } else if (strcmp(_argv[_i], "-wo") == 0) { if (!handle_wo()) return false; } else if (strcmp(_argv[_i], "-c") == 0) { if (!handle_c()) return false; } else if(strcmp(_argv[_i], "-r") == 0) { if (!handle_r()) return false; } else if(strcmp(_argv[_i], "-e") == 0) { if (!handle_e()) return false; } else if (strcmp(_argv[_i], "-v") == 0) { if (!handle_v()) return false; } else if (strcmp(_argv[_i], "-s") == 0) { if (!handle_s()) return false; } else if (strcmp(_argv[_i], "-S") == 0) { if (!handle_S()) return false; } else if (strcmp(_argv[_i], "-loj") == 0) { if (!handle_loj()) return false; } } return ContextBase::parseCmdArgs(argc, argv, _skipFirstArgs); }