Skip to content

Commit 8005771

Browse files
committed
handle REALSXP->STRSXP NaN case explicitly
1 parent 6cf57a8 commit 8005771

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

inst/include/Rcpp/internal/r_coerce.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ inline SEXP r_coerce<CPLXSXP,STRSXP>(Rcomplex from) {
268268
return Rcpp::traits::is_na<CPLXSXP>(from) ? NA_STRING : Rf_mkChar( coerce_to_string<CPLXSXP>( from ) ) ;
269269
}
270270
template <>
271-
inline SEXP r_coerce<REALSXP,STRSXP>(double from){
272-
return Rcpp::traits::is_na<REALSXP>(from) ? NA_STRING :Rf_mkChar( coerce_to_string<REALSXP>( from ) ) ;
271+
inline SEXP r_coerce<REALSXP,STRSXP>(double from){
272+
// handle NaN explicitly
273+
if (R_IsNaN(from)) return Rf_mkChar("NaN");
274+
else return Rcpp::traits::is_na<REALSXP>(from) ? NA_STRING :Rf_mkChar( coerce_to_string<REALSXP>( from ) ) ;
273275
}
274276
template <>
275277
inline SEXP r_coerce<INTSXP ,STRSXP>(int from){

0 commit comments

Comments
 (0)