RcppResultSet              package:Rcpp              R Documentation

_C++ _c_l_a_s_s _f_o_r _s_e_n_d_i_n_g _C++ _o_b_j_e_c_t_s _b_a_c_k _t_o _R

_D_e_s_c_r_i_p_t_i_o_n:

     'RcppResultSet' is a C++ class defined in 'Rcpp.h' that can assign
     any number of C++ objects to R in a single named list object  as
     the 'SEXP' return value of a '.Call()' function call.

     The C++ objects can be of different types that are limited to 
     types  'double',  'int', 'string', vectors of 'double' or 'int'
     (with explicit dimensions), matrices of 'double' or 'int' (with
     explicit dimensions),  STL vectors of 'double', 'int' or 'string',
     STL 'vector of vectors' of types 'double' or 'int' (all with
     implicit dimensions), the internal types 'RcppDate',
     'RcppDateVector', 'RcppStringVector', 'RcppVector' of types
     'double' or 'int', 'RcppMatrix' of types 'double' or 'int' as well
     'RcppFrame', a type that can be converted into a 'data.frame', and
     the R type 'SEXP'. 

     Where applicable, the 'C++' types are automatically converted to
     the corresponding R types structures around types 'numeric',
     'integer', or 'character'.  The 'C++' code can all be retrieved in
     R as elements of a named list object.

_D_e_t_a_i_l_s:

     Usage of 'RcppResultSet' from  'C++' is fully defined in 'Rcpp.h'.
     An example for returning data to R at the end of a '.Call()' call
     follows.

     At the C++ level, the corresponding code to assign these parameter
     to C++ objects is can be as follows (taken from the C++ source of
     'RcppExample'):


       SEXP rl;
       RcppResultSet rs;

       rs.add("date", aDate);        // RcppDate
       rs.add("dateVec", dateVec);   // RcppDateVec
       rs.add("method", method);     // string
       rs.add("tolerance", tol);     // numeric
       rs.add("maxIter", maxIter);   // int
       rs.add("matD", matD);         // RcppMatrix
       rs.add("stlvec", stlvec);     // vector<double> or <int>
       rs.add("stlmat", stlmat);     // vector< vector <double> >
                                     //   or <int>
       rs.add("a", a, nrows, ncols); // double** (or int**) with 
                                     //   two dimension
       rs.add("v", v, len);          // double* (or int*) with 
                                     //   one dimension
       rs.add("stringVec", strVec);  // RcppStringVector
       rs.add("strings", svec);      // vector<string>
       rs.add("InputDF", inframe);   // RcppFrame
       rs.add("PreDF", frame);       // RcppFrame

       rl = rs.getReturnList();
       return(rl);

     As the R level, we assign the returned object a list variables
     from which we select each list element by its name. lookup is
     driven by the names givem at the R level, order is not important. 
     It is however important that the types match. Errors are typically
     caught and an exception is thrown. 

     The class member function 'checkNames' can be used to verify that
     the 'SEXP' object passed to the function contains a given set of
     named object.

_A_u_t_h_o_r(_s):

     Dominick Samperi wrote most of Rcpp during 2005 and 2006.  Dirk
     Eddelbuettel made some additions, and became maintainer in 2008.

_S_e_e _A_l_s_o:

     'RcppExample', the vignette "RcppAPI".

_E_x_a_m_p_l_e_s:

     # example from RcppDate
     # set up date and datetime vectors
     dvec <- Sys.Date() + -2:2
     dtvec <- Sys.time() + (-2:2)*0.5

     # call the underlying  C++ function
     result <- RcppDateExample(dvec, dtvec)

     # inspect returned object
     result

