Example #1
0
//' @rdname convert
//' @export
// [[Rcpp::export]]
Rcpp::CharacterVector icd9DecimalToShort(
		const Rcpp::CharacterVector icd9Decimal) {
	Rcpp::CharacterVector out = clone(icd9Decimal); // clone instead of pushing back thousands of times
  size_t ilen = icd9Decimal.length();
	if (ilen == 0)
		return out;
	for (size_t i = 0; i != ilen; ++i) {
		Rcpp::String strna = icd9Decimal[i]; // need to copy here? does it copy?
		if (strna == NA_STRING || strna == "")
			continue;
		// TODO: Rcpp::String doesn't implement many functions, so using STL. A FAST way
		// might be to use Rcpp::String's function get_cstring, and recode the trim
		// functions to take const char *. This would avoid the type change AND be
		// faster trimming.
		const char * thiscode_cstr = strna.get_cstring();
		std::string thiscode(thiscode_cstr);
		thiscode = trimLeftCpp(thiscode);
		// TODO consider rejecting grossly invalid codes as NA:
		std::size_t pos = thiscode.find_first_of(".");
		if (pos != std::string::npos) {
#ifdef ICD9_DEBUG_TRACE
			Rcpp::Rcout << "found .\n";
#endif
			// now we assume that the major is snug against the left side, so we can add zero padding
			thiscode.erase(pos, 1); // remove the decimal point
			// could do fewer tests on the code by doing this last, but most codes are not V or E...
			if (pos > 0 && pos < 4 && !icd9IsASingleVE(thiscode_cstr)) {
#ifdef ICD9_DEBUG_TRACE
				Rcpp::Rcout << "found numeric\n";
#endif
				thiscode.insert(0, 3 - pos, '0');
			} else if (pos == 2 && icd9IsASingleV(thiscode_cstr)) {
#ifdef ICD9_DEBUG_TRACE
				Rcpp::Rcout << "found V\n";
#endif
				thiscode.insert(1, 1, '0');
				out[i] = thiscode;
			} else if ((pos == 2 || pos == 3) && icd9IsASingleE(thiscode_cstr)) {
#ifdef ICD9_DEBUG_TRACE
				Rcpp::Rcout << "found E\n";
#endif
				thiscode.insert(1, 4 - pos, '0');
			}
			// otherwise leave the code alone
			out[i] = thiscode;

		} else {
			out[i] = Rcpp::String(icd9AddLeadingZeroesMajorSingleStd(thiscode));
		}
	}
	return out;
}
void TimeSeriesPicker::on_buttonBox_accepted()
{
    QStringList id;
    Rcpp::CharacterVector vec = vv->getCharacterVector(vv->getVariableIndex(ui->comboBoxVariableID->currentText()));
    for (int i = 0; i < vec.length(); ++i) {
        id << QString::fromUtf8(vec[i]);
    }
    id.removeDuplicates();
    if (id.length() != vec.length()) {
        QMessageBox::information(this,"Non ID Variable Selected","Please Choose unique variable for ID");
        return;
    }
    if (ui->listWidgetTimes->selectedItems().length() < 2) {
        QMessageBox::information(this,"No Selected time","Please Choose at least two time");
        return;
    }
    QStringList timeList;
    for (int i = 0; i < ui->listWidgetTimes->count(); ++i) {
        if (ui->listWidgetTimes->item(i)->isSelected()) {
            timeList << ui->listWidgetTimes->item(i)->text();
        }
    }
    QString x = ui->comboBoxVariable->currentText();


    vv->sendDataFrameSeriesFormatted(ui->comboBoxVariable->currentText(),ui->comboBoxVariableID->currentText(),timeList,rconn);

      setupChartView("Time Series Plot",x, new QWidget());
      QString command;
      try {
          command = QString("gr<-ggplot(dframe, aes(times, %1 , group = ID, colour = ID)) + geom_line()").arg(x);
          qDebug() << command;
          rconn.parseEvalQ(command.toStdString());
          printGraph(rconn,11,6);
      } catch (...) {

      }
       close();
}
Example #3
0
// [[Rcpp::export]]
bool guessShortPlusFactorCpp(SEXP x_, int n) {
  Rcpp::CharacterVector x;
  switch(TYPEOF(x_)) {
  case STRSXP: {
    x = Rcpp::as<Rcpp::CharacterVector>(x_);
    break;
  }
  case INTSXP: {
    if (Rf_isFactor(x_))
      x = Rf_getAttrib(x_, R_LevelsSymbol);
    break;
  }
  case LGLSXP: {
    // we will accept all logical values, if all are NA, which defauts to
    // logical unless otherwise specified. And we obviously don't know whether
    // these NAs would have been short or long, just default to short.
    Rcpp::LogicalVector xl = Rcpp::LogicalVector(x_);

    if (Rcpp::all(is_na(xl)))
      return true;
    // don't break, because if there were non-NA logicals, this is an error
  }
  default: {
    Rcpp::stop("Character vectors and factors are accepted");
  }
  }
  n = std::min((int)x.length(), n);
  const char * b;
  const char * ob;
  Rcpp::String bs;
  for (R_xlen_t i = 0; i != n; ++i) {
    bs = x[i];
    b = bs.get_cstring();
    ob = b;
    while (*b) {
      if (*b == '.') return false;
      ++b;
    }
    // stop when we first get a five digit code. There are four digit major E codes.
    if ((b - ob) == 5) return true;
  }
  return true;
}
Example #4
0
//' @rdname convert
//' @keywords internal manip
// [[Rcpp::export]]
Rcpp::List icd9DecimalToPartsCpp(const Rcpp::CharacterVector icd9Decimal, const Rcpp::String minorEmpty) {
	Rcpp::CharacterVector majors;
	Rcpp::CharacterVector minors;
	int ilen = icd9Decimal.length();

	if (ilen == 0) {
		return Rcpp::List::create(Rcpp::_["major"] =
				Rcpp::CharacterVector::create(), Rcpp::_["minor"] =
						Rcpp::CharacterVector::create());
	}

	for (Rcpp::CharacterVector::const_iterator it = icd9Decimal.begin();
			it != icd9Decimal.end(); ++it) {
		Rcpp::String strna = *it;
		if (strna == NA_STRING || strna == "") {
			majors.push_back(NA_STRING);
			minors.push_back(NA_STRING);
			continue;
		}
		// TODO: Rcpp::Rcpp::String doesn't implement many functions, so using STL. A FAST way
		// would be to use Rcpp::String's function get_cstring, and recode the trim
		// functions to take const char *. This would avoid the type change AND be
		// faster trimming.
		std::string thiscode = Rcpp::as<std::string>(*it);
		thiscode = strimCpp(thiscode); // This updates 'thisccode' by reference, no copy
		std::size_t pos = thiscode.find(".");
		// substring parts
		std::string majorin;
		Rcpp::String minorout;
		if (pos != std::string::npos) {
			majorin = thiscode.substr(0, pos);
			minorout = thiscode.substr(pos + 1);
		} else {
			majorin = thiscode;
			minorout = minorEmpty;
		}
		majors.push_back(icd9AddLeadingZeroesMajorSingle(majorin));
		minors.push_back(minorout);
	}
	return Rcpp::List::create(Rcpp::_["major"] = majors, Rcpp::_["minor"] =
			minors);
}