Skip to content

Allow implicit conversion to Rcpp::RObject #114

Description

@DavisVaughan

Currently, something like this is allowed with no problems:

SEXP rray__exp_impl(const xt::rarray<rlogical>& x) {
  xt::rarray<double> res = xt::exp(x);
  return res;
}

The (potentially safer) approach would be to return an Rcpp::RObject like this:

Rcpp::RObject rray__exp_impl(const xt::rarray<rlogical>& x) {
  xt::rarray<double> res = xt::exp(x);
  return res;
}

But this gives me a "no viable conversion" error as it does not know how to convert to RObject from xt::rarray<double>. I can do something like this, but it is just a bit annoying:

Rcpp::RObject rray__exp_impl(const xt::rarray<rlogical>& x) {
  xt::rarray<double> res = xt::exp(x);
  return Rcpp::as<Rcpp::RObject>(res);
}

Do you know if its possible to add this implicit conversion?

PS: If you not aware, RObjects are wrappers around SEXPs that Rcpp added that help automatically manage the underlying storage properties (they are also the base class that all core Rcpp classes inherit from). So you don't have to call PROTECT() and UNPROTECT() like you would have to do on the raw R SEXP objects

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions