RcppVector               package:Rcpp               R Documentation

_C++ _c_l_a_s_s_e_s _f_o_r _r_e_c_e_i_v_i_n_g _R _o_b_j_e_c_t _i_n _C++

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

     'RcppVector', 'RcppMatrix' and 'RcppStringVector' are C++ classes
     defined in 'Rcpp.h' that can pass vectors (matrices) of R objects
     of appropriate types to C++ via the '.Call()' function interface. 

     The vector and matrix types are templated and can operate on R
     types 'intger' and 'numeric'. 

     Member functions are provided to query the dimension of the vector
     or matrix object, convert it in a corresponding 'C'
     representation, and also to convert it into a corresponding STL
     object.

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

     Usage of 'RcppVector', 'RcppMatrix' and 'RcppStringVector' in
     'C++' is fully defined in 'Rcpp.h'. 

     As example, consider a call from R to 'C++' such as


       # an R example passing one type of each class to a function
       # someFunction in package somePackage
       val <- .Call("someFunction",
                    rnorm(100),        # numeric vector
                    sample(1:10, 5, TRUE)  # int vector
                    search(),          # character vector
                    as.matrix(rnorm(100),10,10), # matrix
                    PACKAGE="somePackage")

     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 someFunction(SEXP nvec, SEXP ivec,
                         SEXP svec, SEXP nmat) {

         RcppVector<double> nv(nvec);                      
         RcppVector<int>    iv(ivec);
         RcppStringVector   sv(svec);
         RcppMatrix<double> nm(nmat);
       }

     These 'C++' objects could then be queried via


         int n = nv.size();
         int d1 = nm.dim1(), d2 = nm.dim2();

     to retrieve, respectively, vector length and matrix dimensions.

     Moreover, the 'stlVector()' and 'stlMatrix()' member functions can
     be used to convert the objects into STL objects:


         vector<int> ivstl = iv.stlVector();
         vector< vector< double > > = nm.stlMatrix();


_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
     vector <- (seq(1,9))^2

     # call the underlying  C++ function
     result <- RcppVectorExample(vector)

     # inspect returned object
     result

