RcppParams               package:Rcpp               R Documentation

_C++ _c_l_a_s_s _f_o_r _r_e_c_e_i_v_i_n_g (_s_c_a_l_a_r) _p_a_r_a_m_e_t_e_r_s _f_r_o_m _R

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

     'RcppParams' is a C++ class defined in 'Rcpp.h' that receive any
     number of scalar parameters of types in a single named list object
     from R through the '.Call()' function.

     The parameters can be of different types that are limited to the R
     types 'numeric', 'integer', 'character', 'logical' or 'Date'.
     These types are mapped into, respectively, the corresponding C++
     types 'double',  'int', 'string', 'bool' and 'Date' (a custom
     class defined by 'Rcpp'.

_U_s_a_g_e:

       val <- RcppParamsExample(params) 

_A_r_g_u_m_e_n_t_s:

  params: A heterogeneous list specifying 'method' (string),
          'tolerance' (double), 'maxIter' (int) and 'startDate' (Date
          in R, RcppDate in C++).

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

     Usage of 'RcppParams' from R via '.Call()' is as follows:


       # an R example passing one type of each class to a function
       # someFunction in package somePackage
       val <- .Call("someFunction",
                    list(pie=3.1415, magicanswer=42, sometext="foo",
                         yesno=true, today=Sys.date()),
                         PACKAGE="somePackage")

     At the C++ level, the corresponding code to assign these parameter
     to C++ objects is 


       SEXP someFunction(SEXP params) {
         RcppParams par(params);
         double p   = RcppParams.getDoubleValue("pie");
         int magic  = RcppParams.getIntValue("magicanswer");
         string txt = RcppParams.getStringValue("sometext");
         bool yn    = RcppParams.getBoolValue("yesno");
         RcppDate d = RcppParams.getDateValue("today");
         // some calculations ...
         // some return values ...
       }

     As the 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.

_V_a_l_u_e:

     'RcppExample' returns a list containing: 

  method: string input paramter

tolerance: double input paramter

 maxIter: int input parameter

startDate: Date type with starting date

  params: input parameter list (this is redundant because we returned
          the input parameters above)

_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:

     # set up some value
     params <- list(method='BFGS',
                    tolerance=1.0e-5,
                    maxIter=100,
                    startDate=as.Date('2006-7-15'))

     # call the underlying  C++ function
     result <- RcppParamsExample(params)

     # inspect returned object
     result

