Skip to content
Prev 796 / 10988 Next

[Rcpp-devel] About calling C/C++ functions in R

Thanks for your help! When will the new version 0.8.3 be released?




xiagao1982
2010-06-16



???? Romain Francois
????? 2010-06-16 17:15:35
???? xiagao1982
??? rcpp-devel
??? Re: [Rcpp-devel] About calling C/C++ functions in R

Le 16/06/10 10:56, Romain Francois a ?crit :
Done. I added this as a new example "rinside_sample9.cpp".
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
//
// Simple example showing how expose a C++ function
//
// 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
const char* hello( std::string who ){
         std::string result( "hello " ) ;
         result += who ;
         return result.c_str() ;
}
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.parseEval("hello('world')") ;
     std::cout << "hello( 'world') =  " << result << std::endl ;
     exit(0);
}
Romain