Skip to content

Commit 47ed3fe

Browse files
committed
Merge branch 'feature/warnOnCoerce'
2 parents c750a29 + 6c24b84 commit 47ed3fe

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

inst/include/Rcpp/r_cast.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,21 @@ namespace Rcpp{
135135

136136
} // namespace internal
137137

138-
template <int TARGET> SEXP r_cast( SEXP x) {
139-
return (TYPEOF(x)== TARGET) ? x : internal::r_true_cast<TARGET>(x) ;
138+
template <int TARGET> SEXP r_cast(SEXP x) {
139+
if (TYPEOF(x) == TARGET) {
140+
return x;
141+
} else {
142+
#ifndef RCPP_DONT_WARN_ON_COERCE
143+
Shield<SEXP> result( internal::r_true_cast<TARGET>(x) );
144+
Rf_warning("coerced object from '%s' to '%s'",
145+
CHAR(Rf_type2str(TYPEOF(x))),
146+
CHAR(Rf_type2str(TARGET))
147+
);
148+
return result;
149+
#else
150+
return internal::r_true_cast<TARGET>(x);
151+
#endif
152+
}
140153
}
141154

142155
} // namespace Rcpp

0 commit comments

Comments
 (0)