Le 07/12/2019 à 00:29, Qiang Kou a écrit :
What about using "TYPEOF"? Please see R Internals (https://cran.r-project.org/doc/manuals/r-release/R-ints.html#SEXPTYPEs) for more details.
... and if you want to convert integer encoded SEXPTYPE to a human readable string you can use

const char * Rf_type2char(SEXPTYPE);

By the way, conversion in the opposite direction is made by

SEXPTYPE Rf_str2type(const char *);

Best,
Sergueï.


#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
DataFrame rcpp_df(){
   NumericVector   numeric = {1,3};
   IntegerVector   integer = {1,3};
   CharacterVector character = {"B","D"};
   LogicalVector   logical = {false, true};

   DataFrame df = DataFrame::create(Named("numeric") = numeric,
                                 Named("integer") = integer,
                                 Named("character") = character,
                                 Named("logical") = logical);

   Rcpp::Rcout << "numeric:" << TYPEOF(df["numeric"]) << std::endl;
   Rcpp::Rcout << "integer:" << TYPEOF(df["integer"]) << std::endl;
   Rcpp::Rcout << "character:" << TYPEOF(df["character"]) << std::endl;
   Rcpp::Rcout << "logical:" << TYPEOF(df["logical"]) << std::endl;

   return df;
}

/*
 > Rcpp::sourceCpp("test.cc")
 > df <- rcpp_df()
numeric:14
integer:13
character:13
logical:10
*/

On Fri, Dec 6, 2019 at 2:59 PM Brook Milligan <br...@nmsu.edu <mailto:br...@nmsu.edu>> wrote:

    Is there a way to discover the value type for the result of calling
    DataFrame::operator[]?  For example, is there a metafiction that
    will deduce the type?

    A similar question could be asked about the result of calling
    Vector::operator[].

    I understand that these functions actually return a proxy, but it
    would be very helpful to find out the underlying value type.

    Thanks for your help.

    Cheers,
    Brook

    _______________________________________________
    Rcpp-devel mailing list
    Rcpp-devel@lists.r-forge.r-project.org
    <mailto:Rcpp-devel@lists.r-forge.r-project.org>
    https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to