Skip to content

Commit 79c1735

Browse files
committed
some is.na() fixes also thanks to Thomas Tse
1 parent 2e39b2f commit 79c1735

File tree

4 files changed

+44
-35
lines changed

4 files changed

+44
-35
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2013-10-02 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* inst/include/Rcpp/traits/is_na.h: More fixes thanks to Thomas Tse
4+
15
2013-10-01 Dirk Eddelbuettel <edd@debian.org>
26

37
* inst/include/Rcpp/api/meat/is.h: Applied patch by Thomas Tse to

inst/NEWS.Rd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
\title{News for Package 'Rcpp'}
33
\newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
44

5-
\section{Changes in Rcpp version 0.10.5.1 (2013-10-01)}{
5+
\section{Changes in Rcpp version 0.10.5.1 (2013-10-02)}{
66
\itemize{
77
\item Changes in Rcpp API:
88
\itemize{
99
\item Two missing \code{is<>()} templates for
10-
\code{CharacterVector} and \code{CharacterMatrix} have been added
11-
thanks to Thomas Tse.
10+
\code{CharacterVector} and \code{CharacterMatrix} have been added,
11+
and tests for \code{is.na()} have been corrected thanks to Thomas Tse.
1212
}
1313
}
1414
}

inst/THANKS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Dominick Samperi for starting what is now in the RcppClassic package
2525
Oleg Sklyar for the incredibly cool inline package
2626
Alexey Stukalov for a support enabling Intel Compiler 12.0 support
2727
Luke Tierney for helpful discussions on R internals
28-
Thomas Tse for a patch filling in two missing is<T>() instances
28+
Thomas Tse for several patches with small corrections
2929
Simon Urbanek for help on OS X build issues and with R internals
3030
Ken Williams for additional OS X testing
3131
Jelmer Ypma for contributing the Rcout iostreams class patch

inst/include/Rcpp/traits/is_na.h

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22
//
33
// is_na.h: Rcpp R/C++ interface class library -- vector operators
44
//
@@ -23,36 +23,41 @@
2323
#define Rcpp__traits_is_na_h
2424

2525
namespace Rcpp{
26-
namespace traits{
27-
28-
// default to always false, applies to VECSXP, EXPRSXP and RAWSXP
29-
template <int RTYPE>
30-
bool is_na( typename storage_type<RTYPE>::type ){
31-
return false ;
32-
}
33-
34-
template <>
35-
inline bool is_na<INTSXP>( int x ){
36-
return x == NA_INTEGER ;
37-
}
38-
39-
template <>
40-
inline bool is_na<REALSXP>( double x ){
41-
return R_IsNA(x) ;
42-
}
43-
44-
template <>
45-
inline bool is_na<CPLXSXP>( Rcomplex x ){
46-
return R_IsNA(x.r) || R_IsNA(x.i) ;
47-
}
48-
49-
template <>
50-
inline bool is_na<STRSXP>( SEXP x ){ return x == NA_STRING ; }
51-
52-
template <>
53-
inline bool is_na<LGLSXP>( int x ){ return x == NA_LOGICAL ; }
54-
55-
}
26+
27+
namespace traits{
28+
29+
// default to always false, applies to VECSXP, EXPRSXP and RAWSXP
30+
template <int RTYPE>
31+
bool is_na(typename storage_type<RTYPE>::type) {
32+
return false;
33+
}
34+
35+
template <>
36+
inline bool is_na<INTSXP>(int x) {
37+
return x == NA_INTEGER;
38+
}
39+
40+
template <>
41+
inline bool is_na<REALSXP>(double x) {
42+
return R_IsNA(x) || R_IsNaN(x);
43+
}
44+
45+
template <>
46+
inline bool is_na<CPLXSXP>(Rcomplex x) {
47+
return R_IsNA(x.r) || R_IsNA(x.i) || R_IsNaN(x.r) || R_IsNaN(x.i);
48+
}
49+
50+
template <>
51+
inline bool is_na<STRSXP>(SEXP x) {
52+
return false; // see rcpp-devel on 2013-10-02; was: x == NA_STRING;
53+
}
54+
55+
template <>
56+
inline bool is_na<LGLSXP>(int x) {
57+
return x == NA_LOGICAL;
58+
}
59+
60+
}
5661
}
5762

5863
#endif

0 commit comments

Comments
 (0)