本文整理汇总了C++中rcpp::List::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ List::begin方法的具体用法?C++ List::begin怎么用?C++ List::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rcpp::List
的用法示例。
在下文中一共展示了List::begin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: collapsedList
SEXP collapsedList(Rcpp::List ll) {
Rcpp::List::iterator it = ll.begin();
switch(TYPEOF(*it)) {
case REALSXP: {
Rcpp::NumericVector v(ll.begin(), ll.end());
return v;
break; // not reached ...
}
case INTSXP: {
Rcpp::IntegerVector 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;
}
示例2: 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;
}
示例3: countPreClusterMarkers
R_xlen_t countPreClusterMarkers(SEXP preClusterResults_, bool& noDuplicates)
{
Rcpp::List preClusterResults = preClusterResults_;
std::vector<int> markers;
for(Rcpp::List::iterator i = preClusterResults.begin(); i != preClusterResults.end(); i++)
{
Rcpp::IntegerVector Rmarkers = *i;
for(Rcpp::IntegerVector::iterator j = Rmarkers.begin(); j != Rmarkers.end(); j++)
{
markers.push_back(*j);
}
}
R_xlen_t nMarkers1 = markers.size();
std::sort(markers.begin(), markers.end());
std::vector<int>::iterator lastUnique = std::unique(markers.begin(), markers.end());
R_xlen_t nMarkers2 = std::distance(markers.begin(), lastUnique);
noDuplicates = nMarkers1 == nMarkers2;
return nMarkers1;
}
示例4: rcpp_lines_as_network
//' rcpp_lines_as_network
//'
//' Return OSM data in Simple Features format
//'
//' @param sf_lines An sf collection of LINESTRING objects
//' @param pr Rcpp::DataFrame containing the weighting profile
//'
//' @return Rcpp::List objects of OSM data
//'
//' @noRd
// [[Rcpp::export]]
Rcpp::List rcpp_lines_as_network (const Rcpp::List &sf_lines,
Rcpp::DataFrame pr)
{
std::map <std::string, float> profile;
Rcpp::StringVector hw = pr [1];
Rcpp::NumericVector val = pr [2];
for (int i = 0; i != hw.size (); i ++)
profile.insert (std::make_pair (std::string (hw [i]), val [i]));
Rcpp::CharacterVector nms = sf_lines.attr ("names");
if (nms [nms.size () - 1] != "geometry")
throw std::runtime_error ("sf_lines have no geometry component");
if (nms [0] != "osm_id")
throw std::runtime_error ("sf_lines have no osm_id component");
int one_way_index = -1;
int one_way_bicycle_index = -1;
int highway_index = -1;
for (int i = 0; i < nms.size (); i++)
{
if (nms [i] == "oneway")
one_way_index = i;
if (nms [i] == "oneway.bicycle")
one_way_bicycle_index = i;
if (nms [i] == "highway")
highway_index = i;
}
Rcpp::CharacterVector ow = NULL;
Rcpp::CharacterVector owb = NULL;
Rcpp::CharacterVector highway = NULL;
if (one_way_index >= 0)
ow = sf_lines [one_way_index];
if (one_way_bicycle_index >= 0)
owb = sf_lines [one_way_bicycle_index];
if (highway_index >= 0)
highway = sf_lines [highway_index];
if (ow.size () > 0)
{
if (ow.size () == owb.size ())
{
for (unsigned i = 0; i != ow.size (); ++ i)
if (ow [i] == "NA" && owb [i] != "NA")
ow [i] = owb [i];
} else if (owb.size () > ow.size ())
ow = owb;
}
Rcpp::List geoms = sf_lines [nms.size () - 1];
std::vector<bool> isOneWay (geoms.length ());
std::fill (isOneWay.begin (), isOneWay.end (), false);
// Get dimension of matrix
size_t nrows = 0;
int ngeoms = 0;
for (auto g = geoms.begin (); g != geoms.end (); ++g)
{
// Rcpp uses an internal proxy iterator here, NOT a direct copy
Rcpp::NumericMatrix gi = (*g);
int rows = gi.nrow () - 1;
nrows += rows;
if (ngeoms < ow.size ())
{
if (!(ow [ngeoms] == "yes" || ow [ngeoms] == "-1"))
{
nrows += rows;
isOneWay [ngeoms] = true;
}
}
ngeoms ++;
}
Rcpp::NumericMatrix nmat = Rcpp::NumericMatrix (Rcpp::Dimension (nrows, 6));
Rcpp::CharacterMatrix idmat = Rcpp::CharacterMatrix (Rcpp::Dimension (nrows,
3));
nrows = 0;
ngeoms = 0;
int fake_id = 0;
for (auto g = geoms.begin (); g != geoms.end (); ++ g)
{
Rcpp::NumericMatrix gi = (*g);
std::string hway = std::string (highway [ngeoms]);
float hw_factor = profile [hway];
if (hw_factor == 0.0) hw_factor = 1e-5;
hw_factor = 1.0 / hw_factor;
Rcpp::List ginames = gi.attr ("dimnames");
Rcpp::CharacterVector rnms;
if (ginames.length () > 0)
rnms = ginames [0];
else
//.........这里部分代码省略.........