File: rinside_sample9.cpp

package info (click to toggle)
r-cran-rinside 0.2.13-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 604 kB
  • ctags: 592
  • sloc: cpp: 3,155; xml: 57; ansic: 41; makefile: 1
file content (30 lines) | stat: -rw-r--r-- 862 bytes parent folder | download | duplicates (5)
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
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
//
// Simple example showing how expose a C++ function -- no longer builds
//
// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois

#include <RInside.h>                    // for the embedded R via RInside

// a c++ function we wish to expose to R
std::string hello( std::string who ){
    std::string result( "hello " ) ;
    result += who ;
    return result;
} 

int main(int argc, char *argv[]) {

    // create an embedded R instance
    RInside R(argc, argv);               

    // expose the "hello" function in the global environment
    R["hello"] = Rcpp::InternalFunction( &hello ) ;
   
    // call it and display the result
    std::string result = R.parseEvalNT("hello(\"world\")") ;
    std::cout << "hello( 'world') =  " << result << std::endl ; 

    exit(0);
}