是否可以将R函数isTRUE
转换为Rcpp?如果可以,怎么办?
R函数:
function (x)
is.logical(x) && length(x) == 1L && !is.na(x) && x
我在第一部分和第三部分中苦苦挣扎。如何检查输入是布尔型还是逻辑型?当输入类型未知时,如何测试NA?
我知道我可以检查长度是否为1
x.length() == 1 / x.size() == 1
答案 0 :(得分:4)
它已经在this header file中实现为
template <bool NA, typename T>
inline bool is_true( const Rcpp::sugar::SingleLogicalResult<NA,T>& x){
return const_cast< Rcpp::sugar::SingleLogicalResult<NA,T>& >(x).is_true() ;
}
当然引用了another file ...,并且所有模板元编程都不适合胆小的人。您也可以进行素描,请参见this Rcpp Gallery post有关动态分配的信息,以查看在运行时测试类型的示例。