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

Description Usage Arguments Author(s) References See Also Examples

View source: R/cxxfunction.copy.R

Description

Copies the Rcpp function into the working directory.

Usage

1

Arguments

cppfct

Rcpp function

name

Name of the output Rcpp function to be generated

Author(s)

Alexander Robitzsch

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## 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 19, 2017, 7:26 a.m.

Search within the miceadds package
Search all R packages, documentation and source code