Skip to content

Handle passing deflation scheme encoding between R and C++ #60

@Banana1530

Description

@Banana1530

Hmmm.... it looks like the answer is "sort of." The following works, but isn't totally type-safe. We could probably do a more general solution in the future. Issue?

#include "Rcpp.h"

enum DeflationMethod {
  PCA = 0, 
  PLS = 1,  
  CCA = 2
};

namespace Rcpp {
  SEXP wrap(DeflationMethod dm){
    Rcpp::IntegerVector dm_int = Rcpp::wrap(static_cast<int>(dm));
    dm_int.attr("class") = "DeflationMethod"; 
    return dm_int;
  }

  template <> DeflationMethod as(SEXP dm_sexp){
    Rcpp::IntegerVector dm_iv(dm_sexp);
    int dm_int = dm_iv(0); 
    DeflationMethod dm = static_cast<DeflationMethod>(dm_int);
    return dm; 
  }
}

// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::export]]
DeflationMethod make_pls(){
  DeflationMethod pls = DeflationMethod::PLS;
  return pls;
}

// [[Rcpp::export]]
void take_pls(DeflationMethod x){
  Rcpp::Rcout << " x = " << x << std::endl; 
}

Originally posted by @michaelweylandt in #54

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