@@ -72,20 +72,30 @@ class Subsetter {
7272 inline Vector<RTYPE, StoragePolicy> subset_impl ( const VECTOR& this_, const Vector<LGLSXP, OtherStoragePolicy>& x ) const {
7373 Vector<INTSXP, StoragePolicy> tmp = which_na (x);
7474 if (!tmp.size ()) return Vector<RTYPE, StoragePolicy>(0 );
75- else return subset_impl__hidden (this_, tmp);
75+ else return subset_impl (this_, tmp);
7676 }
7777
7878 // Subsetting for characters
7979 template <template <class > class OtherStoragePolicy >
8080 inline Vector<RTYPE, StoragePolicy> subset_impl ( const VECTOR& this_, const Vector<STRSXP, OtherStoragePolicy>& x ) const {
81+
82+ if (Rf_isNull ( Rf_getAttrib (this_, R_NamesSymbol) )) {
83+ int n = x.size ();
84+ Vector<RTYPE, StoragePolicy> output (n);
85+ for (int i=0 ; i < n; ++i) {
86+ output[i] = traits::get_na<RTYPE>();
87+ }
88+ return output;
89+ }
90+
8191 Vector<STRSXP, StoragePolicy> names = as< Vector<STRSXP, StoragePolicy> >(Rf_getAttrib (this_, R_NamesSymbol));
8292 Vector<INTSXP, StoragePolicy> idx = match (x, names); // match returns 1-based index
8393 // apparently, we don't see sugar, so we have to do this manually
8494 Vector<INTSXP, StoragePolicy> idxm1 = no_init (idx.size ());
8595 for (int i=0 ; i < idx.size (); ++i) {
8696 idxm1[i] = idx[i] - 1 ;
8797 }
88- Vector<RTYPE, StoragePolicy> output = subset_impl__hidden (this_, idxm1);
98+ Vector<RTYPE, StoragePolicy> output = subset_impl (this_, idxm1);
8999 int n = output.size ();
90100 if (n == 0 ) return Vector<RTYPE, StoragePolicy>(0 );
91101 Vector<STRSXP, StoragePolicy> out_names = no_init (n);
@@ -100,21 +110,11 @@ class Subsetter {
100110 const VECTOR& vec;
101111 const T& other;
102112
103- private:
104-
105- // Subsetting for integers -- note that it is 0-based
106- template <template <class > class OtherStoragePolicy >
107- inline Vector<RTYPE, StoragePolicy>
108- subset_impl ( const VECTOR this_, const Vector<INTSXP, OtherStoragePolicy>& x ) const {
109- stop (" Subset is not yet implemented for IntegerVectors" );
110- return Vector<RTYPE, StoragePolicy>();
111- }
112-
113113 // Subsetting for integers -- note that it is 0-based
114114 // hidden until we decide whether to go with 0 or 1 based indexing
115115 template <template <class > class OtherStoragePolicy >
116116 inline Vector<RTYPE, StoragePolicy>
117- subset_impl__hidden ( const VECTOR this_, const Vector<INTSXP, OtherStoragePolicy>& x ) const {
117+ subset_impl ( const VECTOR this_, const Vector<INTSXP, OtherStoragePolicy>& x ) const {
118118 int n = x.size ();
119119 if (n == 0 ) return this_;
120120 Vector<RTYPE, StoragePolicy> output = no_init (n);
@@ -124,8 +124,12 @@ class Subsetter {
124124 else if (x[i] > this_.size () - 1 ) output[i] = traits::get_na<RTYPE>();
125125 else output[i] = (this_)[ x[i] ];
126126 }
127+
127128 if (!Rf_isNull ( Rf_getAttrib ( this_, R_NamesSymbol) )) {
128- Vector<STRSXP, StoragePolicy> thisnames = as<Vector<STRSXP, StoragePolicy> >(Rf_getAttrib (this_, R_NamesSymbol));
129+
130+ Vector<STRSXP, StoragePolicy> thisnames =
131+ as<Vector<STRSXP, StoragePolicy> >(Rf_getAttrib (this_, R_NamesSymbol));
132+
129133 Vector<STRSXP, StoragePolicy> outnames = no_init (n);
130134 for (int i=0 ; i < n; ++i) {
131135 if (x[i] == NA_INTEGER) outnames[i] = NA_STRING;
0 commit comments