[Rcpp-devel] Possible error in setequal ??
Søren Højsgaard
sorenh at math.aau.dk
Sat Jan 3 00:13:17 CET 2015
Dear all,
There might be an error in setequal() from sugar. Consider this
#include <Rcpp.h>
using namespace Rcpp;
//[[Rcpp::export]]
bool seteq1(CharacterVector x, CharacterVector y){
return setequal(x,y);
}
//[[Rcpp::export]]
bool seteq2(CharacterVector x, CharacterVector y){
return
(((CharacterVector) setdiff(x,y)).length()==0) &
(((CharacterVector) setdiff(y,x)).length()==0) ;
}
The examples below does not give what I expect when calling seteq1 whereas seteq2 gives what I expect. Am I completely wrong here?
Regards
Søren
seteq1(c(1,2,3), c(3,2,1))
seteq1(c("a","b"), c("a","b"))
seteq1(c(1,2,3), c(3,2))
seteq1(c("a","b"), c("a","b","k"))
seteq2(c(1,2,3), c(3,2,1))
seteq2(c("a","b"), c("a","b"))
seteq2(c(1,2,3), c(3,2))
seteq2(c("a","b"), c("a","b","k"))
> seteq1(c(1,2,3), c(3,2,1))
[1] FALSE
> seteq1(c("a","b"), c("a","b"))
[1] FALSE
> seteq1(c(1,2,3), c(3,2))
[1] FALSE
> seteq1(c("a","b"), c("a","b","k"))
[1] FALSE
> seteq2(c(1,2,3), c(3,2,1))
[1] TRUE
> seteq2(c("a","b"), c("a","b"))
[1] TRUE
> seteq2(c(1,2,3), c(3,2))
[1] FALSE
> seteq2(c("a","b"), c("a","b","k"))
[1] FALSE
More information about the Rcpp-devel
mailing list