Consider these examples using Rcpp
to check various data types. Why does my check for is_list
return FALSE
?
library(Rcpp)
cppFunction('bool is_list(SEXP data) {
return Rf_isList(data) ? true : false;
}')
cppFunction('bool is_data_frame(SEXP x) {
return Rf_inherits(x, "data.frame") ? true : false;
}')
cppFunction('bool is_integer(SEXP data) {
return Rf_isInteger(data) ? true : false;
}')
is_data_frame(list(a = 1))
# [1] FALSE
is_data_frame(data.frame())
# [1] TRUE
is_integer(1)
# [1] FALSE
is_integer(1L)
# [1] TRUE
## However, this is unexpected
is_list(list(a = 1))
[1] FALSE
References
- Rinternals.h isList definition
- this answer that I was working through