RInside Version 0.2.10
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     Rcpp::Rcout << "** rinside_sample9 is currently disabled.\n";
00026     if (FALSE) {
00027         std::string result = R.parseEvalNT("hello(\"world\")") ;
00028         std::cout << "hello( 'world') =  " << result << std::endl ; 
00029     }
00030 
00031     exit(0);
00032 }
00033 
 All Classes Files Functions Variables Enumerations Enumerator Defines