RInside Version 0.2.6
inst/examples/standard/rinside_module_sample0.cpp
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 4; -*-
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 RCPP_MODULE(bling){
00017     using namespace Rcpp ;
00018     function( "hello", &hello );
00019 }
00020 
00021 int main(int argc, char *argv[]) {
00022 
00023     // create an embedded R instance -- and load Rcpp so that modules work
00024     RInside R(argc, argv, true);               
00025         
00026     // load the bling module
00027     R["bling"] = LOAD_RCPP_MODULE(bling) ;
00028     
00029     // call it and display the result
00030     std::string result = R.parseEval("bling$hello('world')") ;
00031     std::cout << "bling$hello( 'world') =  '" << result << "'" << std::endl ; 
00032     exit(0);
00033 }
00034 
 All Classes Files Functions Variables Enumerations Enumerator Defines