cxxfunction.copy: R Utilities: Copy of an 'Rcpp' File

View source: R/cxxfunction.copy.R

cxxfunction.copyR Documentation

R Utilities: 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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v040.i08")}

See Also

inline::cxxfunction

Examples

## Not run: 
#############################################################################
# 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)
    
## End(Not run)

miceadds documentation built on May 29, 2024, 11:05 a.m.