本文整理汇总了C++中rcpp::CharacterVector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ CharacterVector::size方法的具体用法?C++ CharacterVector::size怎么用?C++ CharacterVector::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rcpp::CharacterVector
的用法示例。
在下文中一共展示了CharacterVector::size方法的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: 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);
}
示例3: 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);
}
示例4: 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;
}
示例5: 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 ) ;
}
}
示例6: 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
}
示例7: 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
}
示例8: 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;
}
示例9: 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;
}
示例10: newmajor
// [[Rcpp::export]]
Rcpp::CharacterVector icd9MajMinToShort(const Rcpp::CharacterVector major,
const Rcpp::CharacterVector minor) {
#ifdef ICD9_DEBUG_TRACE
Rcpp::Rcout << "icd9MajMinToShort: major.size() = " << major.size()
<< " and minor.size() = " << minor.size() << "\n";
#endif
if ((major.size() != 1 && major.size() != minor.size())
|| (major.size() == 1 && minor.size() == 0)) {
Rcpp::stop(
"icd9MajMinToShort, length of majors and minors must be equal, unless majors length is one.");
}
if (major.size() == 1) {
#ifdef ICD9_DEBUG_TRACE
Rcpp::Rcout << "icd9MajMinToShort: major.size() = 1\n";
#endif
Rcpp::CharacterVector newmajor(minor.size(), major[0]);
return icd9MajMinToCode(newmajor, minor, true);
}
return icd9MajMinToCode(major, minor, true);
}
示例11: 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
}
示例12: 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;
}
示例13: data
DataFrameSubsetVisitors::DataFrameSubsetVisitors( const Rcpp::DataFrame& data_, const Rcpp::CharacterVector& names ) :
data(data_),
visitors(),
visitor_names(names),
nvisitors(visitor_names.size())
{
std::string name ;
int n = names.size() ;
IntegerVector indices = Language( "match", names, RCPP_GET_NAMES(data) ).fast_eval() ;
for( int i=0; i<n; i++){
int pos = indices[i] ;
if( pos == NA_INTEGER ){
name = (String)names[i] ;
stop( "unknown column '%s' ", name ) ;
}
visitors.push_back(subset_visitor( data[pos-1] )) ;
}
}
示例14: 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 ;
for( int i=0; i<nvisitors; i++){
name_left = names_left[i] ;
name_right = names_right[i] ;
try{
visitors[i] = join_visitor( left[name_left], right[name_right], name_left, name_right, warn ) ;
} catch( const std::exception& ex ){
stop( "cannot join on columns '%s' x '%s': %s ", name_left, name_right, ex.what() ) ;
} catch( ... ){
stop( "cannot join on columns '%s' x '%s'", name_left, name_right ) ;
}
}
}
示例15: hclustCombinedMatrix
SEXP hclustCombinedMatrix(SEXP mpcrossRF_, SEXP preClusterResults_)
{
BEGIN_RCPP
bool noDuplicates;
R_xlen_t preClusterMarkers = countPreClusterMarkers(preClusterResults_, noDuplicates);
if(!noDuplicates)
{
throw std::runtime_error("Duplicate marker indices in call to hclustThetaMatrix");
}
Rcpp::List preClusterResults = preClusterResults_;
Rcpp::S4 mpcrossRF = mpcrossRF_;
Rcpp::S4 rf = mpcrossRF.slot("rf");
Rcpp::RObject lodObject = rf.slot("lod");
if(lodObject.isNULL())
{
throw std::runtime_error("Slot [email protected]@lod cannot be NULL if clusterBy is equal to \"combined\"");
}
Rcpp::S4 lod = Rcpp::as<Rcpp::S4>(lodObject);
Rcpp::S4 theta = rf.slot("theta");
Rcpp::RawVector data = theta.slot("data");
Rcpp::NumericVector levels = theta.slot("levels");
Rcpp::CharacterVector markers = theta.slot("markers");
Rcpp::NumericVector lodData = lod.slot("x");
if(markers.size() != preClusterMarkers || lodData.size() != (preClusterMarkers*(preClusterMarkers+(R_xlen_t)1))/(R_xlen_t)2)
{
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();
//Work out minimum difference between recombination levels
double minDifference = 1;
for(int i = 0; i < levels.size()-1; i++)
{
minDifference = std::min(minDifference, levels[i+1] - levels[i]);
}
double maxLod = *std::max_element(lodData.begin(), lodData.end());
double lodMultiplier = minDifference/maxLod;
//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 + (R_xlen_t)1; row < resultDimension; row++)
{
Rcpp::IntegerVector rowMarkers = preClusterResults(row);
double total = 0;
R_xlen_t counter = 0;
for(int columnMarkerCounter = 0; columnMarkerCounter < columnMarkers.size(); columnMarkerCounter++)
{
R_xlen_t marker1 = columnMarkers[columnMarkerCounter]-(R_xlen_t)1;
for(int 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);
double currentLodDataValue = lodData((column*(column+(R_xlen_t)1))/(R_xlen_t)2 + row);
if(thetaDataValue != 0xFF && currentLodDataValue != NA_REAL && currentLodDataValue == currentLodDataValue)
{
total += levels(thetaDataValue) + (maxLod - currentLodDataValue) *lodMultiplier;
counter++;
}
}
}
if(counter == 0) total = 0.5 + minDifference;
else total /= counter;
result(((resultDimension-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
}