Learn R Programming

miceadds (version 1.6-0)

cxxfunction.copy: RUtilities: Copy of an Rcpp File

Description

Copies the Rcpp function into the working directory.

Usage

cxxfunction.copy(cppfct , name)

Arguments

cppfct
Rcpp function
name
Name of the output Rcpp function to be generated

References

Eddelbuettel, D. & Francois, R. (2011). Rcpp: Seamless R and C++ integration. Journal of Statistical Software, 40(8), 1-18.

See Also

inline::cxxfunction

Examples

Run this code
#############################################################################
# EXAMPLE 1: Rcpp code logistic distribution
#############################################################################

library(Rcpp)
library(inline)
    
# define Rcpp file
code1 <- "
    // input array A
    Rcpp::NumericMatrix AA(A);
    // Rcpp::IntegerVector dimAA(dimA);
    int nrows = AA.nrow();
    int ncolumns = AA.ncol();
    Rcpp::NumericMatrix Alogis(nrows,ncolumns)  ; 
    // compute logistic distribution
    for (int ii=0; ii<nrows; ii++){
        Rcpp::NumericVector h1=AA.row(ii) ;
        Rcpp::NumericVector res = plogis( h1 ) ;
        for (int jj=0;jj<ncolumns;jj++){
            Alogis(ii,jj) = res[jj] ;
                        }
                    }                
    return( wrap(Alogis) );
    "
# compile Rcpp code
fct_rcpp <- inline::cxxfunction( signature( A= "matrix"), code1, 
              plugin = "Rcpp", verbose=TRUE )
# copy function and save it as object 'calclogis'
name <- "calclogis"  # name of the function
cxxfunction.copy( cppfct= fct_rcpp, name=name )
# function is available as object named as name
Reval( paste0( name  , " <- fct_rcpp " ) )
# test function
m1 <- outer( seq( -2 , 2 , len=10 ) , seq(-1.5,1.5 ,len=4) )
calclogis(m1)

Run the code above in your browser using DataLab