本文整理汇总了C++中rcpp::CharacterVector类的典型用法代码示例。如果您正苦于以下问题:C++ CharacterVector类的具体用法?C++ CharacterVector怎么用?C++ CharacterVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CharacterVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: magick_image_write
// [[Rcpp::export]]
Rcpp::RawVector magick_image_write( XPtrImage input, Rcpp::CharacterVector format, Rcpp::IntegerVector quality,
Rcpp::IntegerVector depth, Rcpp::CharacterVector density, Rcpp::CharacterVector comment){
if(!input->size())
return Rcpp::RawVector(0);
XPtrImage image = copy(input);
#if MagickLibVersion >= 0x691
//suppress write warnings see #74 and #116
image->front().quiet(true);
#endif
if(format.size())
for_each ( image->begin(), image->end(), Magick::magickImage(std::string(format[0])));
if(quality.size())
for_each ( image->begin(), image->end(), Magick::qualityImage(quality[0]));
if(depth.size())
for_each ( image->begin(), image->end(), Magick::depthImage(depth[0]));
if(density.size()){
for_each ( image->begin(), image->end(), Magick::resolutionUnitsImage(Magick::PixelsPerInchResolution));
for_each ( image->begin(), image->end(), Magick::densityImage(Point(density[0])));
}
if(comment.size())
for_each ( image->begin(), image->end(), Magick::commentImage(std::string(comment.at(0))));
Magick::Blob output;
writeImages( image->begin(), image->end(), &output );
Rcpp::RawVector res(output.length());
std::memcpy(res.begin(), output.data(), output.length());
return res;
}
示例2: rawSymmetricMatrixToDist
SEXP rawSymmetricMatrixToDist(SEXP object)
{
BEGIN_RCPP
Rcpp::S4 rawSymmetric = object;
Rcpp::NumericVector levels = Rcpp::as<Rcpp::NumericVector>(rawSymmetric.slot("levels"));
Rcpp::CharacterVector markers = Rcpp::as<Rcpp::CharacterVector>(rawSymmetric.slot("markers"));
Rcpp::RawVector data = Rcpp::as<Rcpp::RawVector>(rawSymmetric.slot("data"));
R_xlen_t size = markers.size(), levelsSize = levels.size();
Rcpp::NumericVector result(size*(size - 1)/2, 0);
int counter = 0;
for(R_xlen_t row = 0; row < size; row++)
{
for(R_xlen_t column = row+1; column < size; column++)
{
int byte = data(column * (column + (R_xlen_t)1)/(R_xlen_t)2 + row);
if(byte == 255) result(counter) = std::numeric_limits<double>::quiet_NaN();
else result(counter) = levels(byte);
counter++;
}
}
result.attr("Size") = (int)size;
result.attr("Labels") = markers;
result.attr("Diag") = false;
result.attr("Upper") = false;
result.attr("class") = "dist";
return result;
END_RCPP
}
示例3: major
//' @rdname convert
//' @keywords internal manip
// [[Rcpp::export]]
Rcpp::List icd9ShortToPartsCpp(const Rcpp::CharacterVector icd9Short, const Rcpp::String minorEmpty) {
Rcpp::CharacterVector major(icd9Short.size());
Rcpp::CharacterVector minor(icd9Short.size());
for (int i = 0; i < icd9Short.size(); ++i) {
Rcpp::String thisShort = icd9Short[i];
if (thisShort == NA_STRING) { // .is_na() is private?
minor[i] = NA_STRING; // I think set_na() might be an alternative.
continue;
}
std::string s(thisShort.get_cstring()); // TODO maybe better to use as?
s = strimCpp(s); // in place or rewrite?
std::string::size_type sz = s.size();
if (icd9IsASingleE(s.c_str())) { // E code
switch (sz) {
case 2:
case 3:
case 4:
major[i] = s.substr(0, sz);
minor[i] = minorEmpty;
break;
case 5:
major[i] = s.substr(0, 4);
minor[i] = s.substr(4, 1);
break;
default:
major[i] = NA_STRING;
minor[i] = NA_STRING;
continue;
}
} else { // not an E code
switch (sz) {
case 1:
case 2:
case 3:
major[i] = s.substr(0, sz);
minor[minorEmpty];
continue;
case 4:
case 5:
major[i] = s.substr(0, 3);
minor[i] = s.substr(3, sz - 3);
continue;
default:
major[i] = NA_STRING;
minor[i] = NA_STRING;
continue;
}
}
} // for
return icd9MajMinToParts(icd9AddLeadingZeroesMajor(major), minor);
}
示例4: hclustThetaMatrix
SEXP hclustThetaMatrix(SEXP mpcrossRF_, SEXP preClusterResults_)
{
BEGIN_RCPP
Rcpp::List preClusterResults = preClusterResults_;
bool noDuplicates;
R_xlen_t preClusterMarkers = countPreClusterMarkers(preClusterResults_, noDuplicates);
if(!noDuplicates)
{
throw std::runtime_error("Duplicate marker indices in call to hclustThetaMatrix");
}
Rcpp::S4 mpcrossRF = mpcrossRF_;
Rcpp::S4 rf = mpcrossRF.slot("rf");
Rcpp::S4 theta = rf.slot("theta");
Rcpp::RawVector data = theta.slot("data");
Rcpp::NumericVector levels = theta.slot("levels");
Rcpp::CharacterVector markers = theta.slot("markers");
if(markers.size() != preClusterMarkers)
{
throw std::runtime_error("Number of markers in precluster object was inconsistent with number of markers in mpcrossRF object");
}
R_xlen_t resultDimension = preClusterResults.size();
//Allocate enough storage. This symmetric matrix stores the *LOWER* triangular part, in column-major storage. Excluding the diagonal.
Rcpp::NumericVector result(((resultDimension-(R_xlen_t)1)*resultDimension)/(R_xlen_t)2);
for(R_xlen_t column = 0; column < resultDimension; column++)
{
Rcpp::IntegerVector columnMarkers = preClusterResults(column);
for(R_xlen_t row = column + 1; row < resultDimension; row++)
{
Rcpp::IntegerVector rowMarkers = preClusterResults(row);
double total = 0;
R_xlen_t counter = 0;
for(R_xlen_t columnMarkerCounter = 0; columnMarkerCounter < columnMarkers.size(); columnMarkerCounter++)
{
R_xlen_t marker1 = columnMarkers[columnMarkerCounter]-(R_xlen_t)1;
for(R_xlen_t rowMarkerCounter = 0; rowMarkerCounter < rowMarkers.size(); rowMarkerCounter++)
{
R_xlen_t marker2 = rowMarkers[rowMarkerCounter]-(R_xlen_t)1;
R_xlen_t column = std::max(marker1, marker2);
R_xlen_t row = std::min(marker1, marker2);
Rbyte thetaDataValue = data((column*(column+(R_xlen_t)1))/(R_xlen_t)2 + row);
if(thetaDataValue != 0xFF)
{
total += levels(thetaDataValue);
counter++;
}
}
}
if(counter == 0) total = 0.5;
else total /= counter;
result(((resultDimension-(R_xlen_t)1)*resultDimension)/(R_xlen_t)2 - ((resultDimension - column)*(resultDimension-column-(R_xlen_t)1))/(R_xlen_t)2 + row-column-(R_xlen_t)1) = total;
}
}
return result;
END_RCPP
}
示例5: CPL_sfc_from_wkt
// [[Rcpp::export]]
Rcpp::List CPL_sfc_from_wkt(Rcpp::CharacterVector wkt) {
std::vector<OGRGeometry *> g(wkt.size());
OGRGeometryFactory f;
for (int i = 0; i < wkt.size(); i++) {
char *wkt_str = wkt(i);
#if GDAL_VERSION_MAJOR <= 2 && GDAL_VERSION_MINOR <= 2
handle_error(f.createFromWkt(&wkt_str, NULL, &(g[i])));
#else
handle_error(f.createFromWkt( (const char*) wkt_str, NULL, &(g[i])));
#endif
}
return sfc_from_ogr(g, true);
}
示例6: constructDissimilarityMatrix
SEXP constructDissimilarityMatrix(SEXP object, SEXP clusters_)
{
BEGIN_RCPP
Rcpp::S4 rawSymmetric = object;
Rcpp::NumericVector levels = Rcpp::as<Rcpp::NumericVector>(rawSymmetric.slot("levels"));
Rcpp::CharacterVector markers = Rcpp::as<Rcpp::CharacterVector>(rawSymmetric.slot("markers"));
Rcpp::RawVector data = Rcpp::as<Rcpp::RawVector>(rawSymmetric.slot("data"));
int nMarkers = markers.size();
std::vector<double> levelsCopied = Rcpp::as<std::vector<double> >(levels);
std::vector<int> permutation(nMarkers);
for(int i = 0; i < nMarkers; i++) permutation[i] = i;
return constructDissimilarityMatrixInternal(&(data(0)), levelsCopied, nMarkers, clusters_, 0, permutation);
END_RCPP
}
示例7: left
DataFrameJoinVisitors::DataFrameJoinVisitors(const Rcpp::DataFrame& left_, const Rcpp::DataFrame& right_, Rcpp::CharacterVector names_left, Rcpp::CharacterVector names_right, bool warn_ ) :
left(left_), right(right_),
visitor_names_left(names_left),
visitor_names_right(names_right),
nvisitors(names_left.size()),
visitors(nvisitors),
warn(warn_)
{
std::string name_left, name_right ;
IntegerVector indices_left = Language( "match", names_left, RCPP_GET_NAMES(left) ).fast_eval() ;
IntegerVector indices_right = Language( "match", names_right, RCPP_GET_NAMES(right) ).fast_eval() ;
for( int i=0; i<nvisitors; i++){
name_left = names_left[i] ;
name_right = names_right[i] ;
if( indices_left[i] == NA_INTEGER ){
stop( "'%s' column not found in lhs, cannot join" ) ;
}
if( indices_right[i] == NA_INTEGER ){
stop( "'%s' column not found in rhs, cannot join" ) ;
}
visitors[i] = join_visitor( left[indices_left[i]-1], right[indices_right[i]-1], name_left, name_right, warn ) ;
}
}
示例8: ret
std::vector<char *> create_options(Rcpp::CharacterVector lco, bool quiet) {
if (lco.size() == 0)
quiet = true; // nothing to report
if (! quiet)
Rcpp::Rcout << "options: "; // #nocov
std::vector<char *> ret(lco.size() + 1);
for (int i = 0; i < lco.size(); i++) {
ret[i] = (char *) (lco[i]);
if (! quiet)
Rcpp::Rcout << ret[i] << " "; // #nocov
}
ret[lco.size()] = NULL;
if (! quiet)
Rcpp::Rcout << std::endl; // #nocov
return ret;
}
示例9: parse_gb_qualifiers
Rcpp::CharacterVector parse_gb_qualifiers(
const std::vector<std::string>& qualifiers )
{
int begin_, end_;
std::vector<std::string> names, values;
names.reserve( qualifiers.size() );
values.reserve( qualifiers.size() );
std::vector<std::string>::const_iterator s_it = std::begin(qualifiers);
for ( ; s_it != std::end( qualifiers ); s_it++ ) {
begin_ = s_it->find_first_not_of("=");
end_ = s_it->find_first_of( "=", begin_ );
names.push_back( s_it->substr( begin_, end_ ) );
values.push_back( trim( s_it->substr(end_ + 1, s_it->length() - end_), "\"") );
}
Rcpp::CharacterVector Values = Rcpp::CharacterVector( std::begin(values), std::end(values) );
Values.names() = names;
return Values;
}
示例10: collapsedList
SEXP collapsedList(Rcpp::List ll) {
if (ll.length() == 0) return R_NilValue;
Rcpp::List::iterator it = ll.begin();
switch(TYPEOF(*it)) {
case REALSXP: {
Rcpp::NumericVector v(ll.begin(), ll.end());
Rcpp::RObject ro = ll[0];
if (ro.hasAttribute("class")) {
Rcpp::CharacterVector cv = ro.attr("class");
if ((cv.size() == 1) && std::string(cv[0]) == "Date") {
Rcpp::DateVector dv(v);
return dv;
}
if ((cv.size() == 2) && std::string(cv[1]) == "POSIXt") {
Rcpp::DatetimeVector dtv(v);
return dtv;
}
}
return v;
break; // not reached ...
}
case INTSXP: {
Rcpp::IntegerVector v(ll.begin(), ll.end());
return v;
break; // not reached ...
}
case LGLSXP: {
Rcpp::LogicalVector v(ll.begin(), ll.end());
return v;
break; // not reached ...
}
case STRSXP: { // minor code smell that this is different :-/
int n = ll.size();
Rcpp::CharacterVector v(n);
for (int i=0; i<n; i++) {
std::string s = Rcpp::as<std::string>(ll[i]);
v[i] = s;
}
return v;
break; // not reached ...
}
}
return ll;
}
示例11: magick_image_readbin
// [[Rcpp::export]]
XPtrImage magick_image_readbin(Rcpp::RawVector x, Rcpp::CharacterVector density, Rcpp::IntegerVector depth, bool strip = false){
XPtrImage image = create();
#if MagickLibVersion >= 0x689
Magick::ReadOptions opts = Magick::ReadOptions();
#if MagickLibVersion >= 0x690
opts.quiet(1);
#endif
if(density.size())
opts.density(std::string(density.at(0)).c_str());
if(depth.size())
opts.depth(depth.at(0));
Magick::readImages(image.get(), Magick::Blob(x.begin(), x.length()), opts);
#else
Magick::readImages(image.get(), Magick::Blob(x.begin(), x.length()));
#endif
if(strip)
for_each (image->begin(), image->end(), Magick::stripImage());
return image;
}
示例12: guessShortPlusFactorCpp
// [[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;
}
示例13: magick_image_readpath
// [[Rcpp::export]]
XPtrImage magick_image_readpath(Rcpp::CharacterVector paths, Rcpp::CharacterVector density, Rcpp::IntegerVector depth, bool strip = false){
XPtrImage image = create();
#if MagickLibVersion >= 0x689
Magick::ReadOptions opts = Magick::ReadOptions();
#if MagickLibVersion >= 0x690
opts.quiet(1);
#endif
if(density.size())
opts.density(std::string(density.at(0)).c_str());
if(depth.size())
opts.depth(depth.at(0));
for(int i = 0; i < paths.size(); i++)
Magick::readImages(image.get(), std::string(paths[i]), opts);
#else
for(int i = 0; i < paths.size(); i++)
Magick::readImages(image.get(), std::string(paths[i]));
#endif
if(strip)
for_each (image->begin(), image->end(), Magick::stripImage());
return image;
}
示例14: thiscode
//' @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;
}
示例15: on_buttonBox_accepted
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();
}