RInside Version 0.2.6
inst/examples/standard/rinside_sample9.cpp
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
00002 //
00003 // Simple example showing how expose a C++ function
00004 //
00005 // Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
00006 
00007 #include <RInside.h>                    // for the embedded R via RInside
00008 
00009 // a c++ function we wish to expose to R
00010 const char* hello( std::string who ){
00011         std::string result( "hello " ) ;
00012         result += who ;
00013         return result.c_str() ;
00014 } 
00015 
00016 int main(int argc, char *argv[]) {
00017 
00018     // create an embedded R instance
00019     RInside R(argc, argv);               
00020 
00021     // expose the "hello" function in the global environment
00022     R["hello"] = Rcpp::InternalFunction( &hello ) ;
00023    
00024     // call it and display the result
00025     std::string result = R.parseEval("hello('world')") ;
00026     std::cout << "hello( 'world') =  " << result << std::endl ; 
00027 
00028     exit(0);
00029 }
00030 
 All Classes Files Functions Variables Enumerations Enumerator Defines