Skip to content

Commit 1ebac33

Browse files
committed
Some minor tweaks
1 parent 0da7155 commit 1ebac33

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

inst/include/Rcpp/vector/Subsetter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace Rcpp {
7373
template <template <class> class OtherStoragePolicy>
7474
inline Vector<RTYPE, StoragePolicy> subset_impl( const VECTOR& this_, const Vector<LGLSXP, OtherStoragePolicy>& x ) const {
7575
if (this_.size() != x.size()) {
76-
stop("unequal vector sizes");
76+
stop("subsetting with a LogicalVector requires both vectors to be of equal size");
7777
}
7878
Vector<INTSXP, StoragePolicy> tmp = which_na(x);
7979
if (!tmp.size()) return Vector<RTYPE, StoragePolicy>(0);
@@ -85,7 +85,7 @@ namespace Rcpp {
8585
inline Vector<RTYPE, StoragePolicy> subset_impl( const VECTOR& this_, const Vector<STRSXP, OtherStoragePolicy>& x ) const {
8686

8787
if (Rf_isNull( Rf_getAttrib(this_, R_NamesSymbol) )) {
88-
stop("Tried to subset a vector with no names using a CharacterVector");
88+
stop("can't subset a nameless vector using a CharacterVector");
8989
}
9090

9191
Vector<STRSXP, StoragePolicy> names = as< Vector<STRSXP, StoragePolicy> >(Rf_getAttrib(this_, R_NamesSymbol));

inst/unitTests/cpp/Subset.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ NumericVector subset_test_int(NumericVector x, IntegerVector y) {
66
return x[y];
77
}
88

9+
// [[Rcpp::export]]
10+
NumericVector subset_test_num(NumericVector x, NumericVector y) {
11+
return x[y];
12+
}
13+
914
// [[Rcpp::export]]
1015
NumericVector subset_test_lgcl(NumericVector x, LogicalVector y) {
1116
return x[y];

inst/unitTests/runit.subset.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ if (.runThisTest) {
3333
checkException( subset_test_int(x, -1L) )
3434
checkException( subset_test_int(x, length(x)) )
3535

36+
checkIdentical( x[c(1, 2, 3)], subset_test_num(x, c(0, 1, 2)),
37+
"numeric subsetting")
38+
3639
checkIdentical( x[ c('b', 'a') ], subset_test_char(x, c('b', 'a')),
3740
"character subsetting")
3841

0 commit comments

Comments
 (0)