How to return R's NULL in Rcpp code?

随声附和 提交于 2019-12-09 15:52:26

问题


Suppose I have a C++ code to compile with Rcpp and will be called in R.

// [[Rcpp::export]]
SEXP to_env(List x) {
  if(x.hasAttribute("names"))
  {
    return x;
  }
  else
  {
    return NULL;
  }
}

What should the NULL value be to return R's NULL instead of a crash?


回答1:


Use this code:

return R_NilValue;


来源:https://stackoverflow.com/questions/25658225/how-to-return-rs-null-in-rcpp-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!