22#ifndef Rcpp_vector_Subsetter_h_
23#define Rcpp_vector_Subsetter_h_
30 int RTYPE,
template <
class>
class StoragePolicy,
31 int RHS_RTYPE,
bool RHS_NA,
typename RHS_T
54 template <
int OtherRTYPE,
template <
class>
class OtherStoragePolicy>
56 R_xlen_t n = other.
size();
63 for (R_xlen_t i=0; i < n; ++i) {
102 template <
int RTYPE_OTHER,
template <
class>
class StoragePolicyOther,
int RHS_RTYPE_OTHER,
bool RHS_NA_OTHER,
typename RHS_T_OTHER>
130 operator SEXP()
const {
136 template <
typename IDX>
138#ifndef RCPP_NO_BOUNDS_CHECK
139 for (IDX i=0; i < n; ++i) {
140 if (x[i] < 0 or x[i] >= size) {
141 if(std::numeric_limits<IDX>::is_integer && size > std::numeric_limits<IDX>::max()) {
142 stop(
"use NumericVector to index an object of length %td", size);
152 int* ptr = INTEGER(
rhs);
154 for (R_xlen_t i=0; i <
rhs_n; ++i) {
162 std::vector<R_xlen_t> tmp(
rhs.size());
163 for(
size_t i = 0 ; i < tmp.size() ; ++i) {
167 for (R_xlen_t i=0; i <
rhs_n; ++i) {
175 SEXP names = Rf_getAttrib(
lhs, R_NamesSymbol);
176 if (Rf_isNull(names))
stop(
"names is null");
179 for (R_xlen_t i = 0; i <
rhs_n; ++i) {
180 const SEXP*
match = std::find(namesPtr, namesPtr +
lhs_n, *(rhsPtr + i));
191 stop(
"logical subsetting requires vectors of identical size");
193 int* ptr = LOGICAL(
rhs);
194 for (R_xlen_t i=0; i <
rhs_n; ++i) {
195 if (ptr[i] == NA_INTEGER) {
196 stop(
"can't subset using a logical vector with NAs");
210 SEXP names = Rf_getAttrib(
lhs, R_NamesSymbol);
211 if (!Rf_isNull(names)) {
214 SET_STRING_ELT(out_names, i, STRING_ELT(names,
indices[i]));
216 Rf_setAttrib(output, R_NamesSymbol, out_names);
218 Rf_copyMostAttrib(
lhs, output);
234#define RCPP_GENERATE_SUBSET_PROXY_OPERATOR(__OPERATOR__) \
235 template <int RTYPE_OTHER, template <class> class StoragePolicyOther, \
236 int RHS_RTYPE_OTHER, bool RHS_NA_OTHER, typename RHS_T_OTHER> \
237 Vector<RTYPE, StoragePolicy> operator __OPERATOR__ ( \
238 const SubsetProxy<RTYPE_OTHER, StoragePolicyOther, RHS_RTYPE_OTHER, \
239 RHS_NA_OTHER, RHS_T_OTHER>& other) { \
240 Vector<RTYPE, StoragePolicy> result(indices_n); \
241 if (other.indices_n == 1) { \
242 for (R_xlen_t i = 0; i < indices_n; ++i) \
243 result[i] = lhs[indices[i]] __OPERATOR__ other.lhs[other.indices[0]]; \
244 } else if (indices_n == other.indices_n) { \
245 for (R_xlen_t i = 0; i < indices_n; ++i) \
246 result[i] = lhs[indices[i]] __OPERATOR__ other.lhs[other.indices[i]]; \
248 stop("index error"); \
258#undef RCPP_GENERATE_SUBSET_PROXY_OPERATOR
#define RCPP_GENERATE_SUBSET_PROXY_OPERATOR(__OPERATOR__)
SubsetProxy & operator=(bool other)
void get_indices(traits::identity< traits::int2type< REALSXP > > t)
void get_indices(traits::identity< traits::int2type< STRSXP > > t)
SubsetProxy & operator=(const char *other)
void get_indices(traits::identity< traits::int2type< LGLSXP > > t)
SubsetProxy & operator=(int other)
SubsetProxy & operator=(const SubsetProxy< RTYPE_OTHER, StoragePolicyOther, RHS_RTYPE_OTHER, RHS_NA_OTHER, RHS_T_OTHER > &other)
SubsetProxy & operator=(const Vector< OtherRTYPE, OtherStoragePolicy > &other)
SubsetProxy & operator=(double other)
void check_indices(IDX *x, R_xlen_t n, R_xlen_t size)
void get_indices(traits::identity< traits::int2type< INTSXP > > t)
SubsetProxy(const SubsetProxy &other)
Vector< RTYPE, StoragePolicy > get_vec() const
std::vector< R_xlen_t > indices
SubsetProxy & operator=(const SubsetProxy &other)
SubsetProxy(LHS_t &lhs_, const RHS_t &rhs_)
Vector< RHS_RTYPE, StoragePolicy > RHS_t
Vector< RTYPE, StoragePolicy > LHS_t
void NORET stop(const std::string &message)
no_init_vector no_init(R_xlen_t size)
IntegerVector match(const VectorBase< RTYPE, NA, T > &x, const VectorBase< RTYPE, RHS_NA, RHS_T > &table_)
SEXP wrap(const Date &date)