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 #ifndef RCPP_NO_BOUNDS_CHECK
137 template <
typename IDX>
139 for (IDX i=0; i < n; ++i) {
140 if (x[i] < 0 or x[i] >= size) {
142 stop(
"use NumericVector to index an object of length %td", size);
149 template <
typename IDX>
155 int* ptr = INTEGER(
rhs);
157 for (R_xlen_t i=0; i <
rhs_n; ++i) {
165 std::vector<R_xlen_t> tmp(
rhs.
size());
166 for(
size_t i = 0 ; i < tmp.size() ; ++i) {
170 for (R_xlen_t i=0; i <
rhs_n; ++i) {
178 SEXP names = Rf_getAttrib(
lhs, R_NamesSymbol);
179 if (Rf_isNull(names))
stop(
"names is null");
180 SEXP* namesPtr = STRING_PTR(names);
181 SEXP* rhsPtr = STRING_PTR(
rhs);
182 for (R_xlen_t i = 0; i <
rhs_n; ++i) {
194 stop(
"logical subsetting requires vectors of identical size");
196 int* ptr = LOGICAL(
rhs);
197 for (R_xlen_t i=0; i <
rhs_n; ++i) {
198 if (ptr[i] == NA_INTEGER) {
199 stop(
"can't subset using a logical vector with NAs");
213 SEXP names = Rf_getAttrib(
lhs, R_NamesSymbol);
214 if (!Rf_isNull(names)) {
217 SET_STRING_ELT(out_names, i, STRING_ELT(names,
indices[i]));
219 Rf_setAttrib(output, R_NamesSymbol, out_names);
221 Rf_copyMostAttrib(
lhs, output);
237 #define RCPP_GENERATE_SUBSET_PROXY_OPERATOR(__OPERATOR__) \
238 template <int RTYPE_OTHER, template <class> class StoragePolicyOther, \
239 int RHS_RTYPE_OTHER, bool RHS_NA_OTHER, typename RHS_T_OTHER> \
240 Vector<RTYPE, StoragePolicy> operator __OPERATOR__ ( \
241 const SubsetProxy<RTYPE_OTHER, StoragePolicyOther, RHS_RTYPE_OTHER, \
242 RHS_NA_OTHER, RHS_T_OTHER>& other) { \
243 Vector<RTYPE, StoragePolicy> result(indices_n); \
244 if (other.indices_n == 1) { \
245 for (R_xlen_t i = 0; i < indices_n; ++i) \
246 result[i] = lhs[indices[i]] __OPERATOR__ other.lhs[other.indices[0]]; \
247 } else if (indices_n == other.indices_n) { \
248 for (R_xlen_t i = 0; i < indices_n; ++i) \
249 result[i] = lhs[indices[i]] __OPERATOR__ other.lhs[other.indices[i]]; \
251 stop("index error"); \
261 #undef RCPP_GENERATE_SUBSET_PROXY_OPERATOR
#define RCPP_GENERATE_SUBSET_PROXY_OPERATOR(__OPERATOR__)
void get_indices(traits::identity< traits::int2type< REALSXP > > t)
SubsetProxy & operator=(const Vector< OtherRTYPE, OtherStoragePolicy > &other)
SubsetProxy & operator=(int other)
void get_indices(traits::identity< traits::int2type< STRSXP > > t)
void get_indices(traits::identity< traits::int2type< LGLSXP > > t)
SubsetProxy & operator=(bool other)
SubsetProxy & operator=(const char *other)
Vector< RTYPE, StoragePolicy > get_vec() const
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)
std::vector< R_xlen_t > indices
SubsetProxy & operator=(const SubsetProxy &other)
SubsetProxy & operator=(double other)
SubsetProxy(LHS_t &lhs_, const RHS_t &rhs_)
Vector< RHS_RTYPE, StoragePolicy > RHS_t
SubsetProxy & operator=(const SubsetProxy< RTYPE_OTHER, StoragePolicyOther, RHS_RTYPE_OTHER, RHS_NA_OTHER, RHS_T_OTHER > &other)
Vector< RTYPE, StoragePolicy > LHS_t
traits::enable_if< helpers::decays_to_ctype< typename std::iterator_traits< InputIterator >::value_type >::value, typename helpers::ctype< typename std::iterator_traits< InputIterator >::value_type >::type >::type max(InputIterator begin, InputIterator end)
no_init_vector no_init(R_xlen_t size)
SEXP find(const std::string &name) const
void NORET stop(const char *fmt, Args &&... args)
IntegerVector match(const VectorBase< RTYPE, NA, T > &x, const VectorBase< RTYPE, RHS_NA, RHS_T > &table_)
SEXP wrap(const Date &date)