Skip to content

Commit c07fced

Browse files
committed
fix LogicalVector construction from bool
1 parent 127a6f1 commit c07fced

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2014-09-13 Kevin Ushey <kevinushey@gmail.com>
2+
3+
* inst/include/Rcpp/vector/Vector.h: Allow logical vectors to be created
4+
from bools
5+
* inst/unitTests/runit.Vector.R: Idem
6+
* inst/unitTests/cpp/Vector.cpp: Idem
7+
18
2014-09-13 Dirk Eddelbuettel <edd@debian.org>
29

310
* inst/skeleton/Rcpp_modules_examples.Rd: Added to document modules examples

inst/include/Rcpp/vector/Vector.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ class Vector :
119119
}
120120
}
121121

122+
template <typename T = typename Rcpp::traits::if_<RTYPE == LGLSXP, bool, void>::type>
123+
Vector(bool value) {
124+
Storage::set__(Rf_allocVector(RTYPE, 1));
125+
fill(value);
126+
}
127+
122128
template <typename U>
123129
Vector( const Dimension& dims, const U& u) {
124130
RCPP_DEBUG_2( "Vector<%d>( const Dimension& (%d), const U& )", RTYPE, dims.size() )

inst/unitTests/cpp/Vector.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,14 @@ List list_sexp_assign(SEXP x) {
750750
L = x;
751751
return L;
752752
}
753+
754+
// [[Rcpp::export]]
755+
bool logical_vector_from_bool() {
756+
return true;
757+
}
758+
759+
// [[Rcpp::export]]
760+
LogicalVector logical_vector_from_bool_assign() {
761+
LogicalVector result = true;
762+
return result;
763+
}

inst/unitTests/runit.Vector.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,14 @@ if (.runThisTest) {
665665
other <- list_sexp_assign(l)
666666
checkIdentical(l, other)
667667
}
668+
669+
test.logical.vector.from.bool <- function() {
670+
checkIdentical(logical_vector_from_bool(), TRUE)
671+
}
672+
673+
test.logical.vector.from.bool.assign <- function() {
674+
checkIdentical(logical_vector_from_bool_assign(), TRUE)
675+
}
668676

669677
}
670678

0 commit comments

Comments
 (0)