Dirk's code relates to a question I meant to ask the experts for a while: what's a safe and generic way to print C/C++ objects in an R session?
The background: forwarding the cout-stream in Dirk's example to R as below doesn't work in the R-GUI on Windows (or in an IDE such as Eclipse); but it does work if one runs an R session from the command line (that is, within the console -- no surprise that the stream is correctly forwarded). Additionally, there's a (confusing) variety of other print-functions that successfully bridge the gap between C functions and the R-GUI, mostly made available through prtutil.h. For instance, Rf_PrintValue takes an SEXP and prints it to R using the "right format" when used in any C/C++-function, whereas functions such as Rf_printIntegerVector take C arguments (and somehow smuggle them into the R session). And then there's the workhorse Rprintf (which is possibly called by Rf_printIntegerVector). Apologies for being so vague -- I would say I am eventually looking for a way to make the below example run in the R-GUI, both to avoid using the abovementioned functions, and to use existing C++-code that contains summary/debugging overloads of cout. (This may belong to Rd and not to Rcpp-devel, but I'm not sure.) Best, Jo 2010/10/28 Dirk Eddelbuettel <[email protected]> > > First, I (re-)define your helper function, making the argument const: > > > ## define our helper function, this will be passed as an include segment > to cxxfunction() > > inc <- 'void other(const double any) { > + std::cout << "YAY it works, value is " << any << std::endl; > + } > + ' > > > And use it: > > num <- 42.1337 > > fun(num) > YAY it works, value is 42.1337 > YAY it works, value is 42.1337 > [1] 0 > > fun(3.1415) > YAY it works, value is 3.1415 > YAY it works, value is 3.1415 > [1] 0 > > >
_______________________________________________ Rcpp-devel mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
