[Rd] printf capture

Simon Urbanek simon.urbanek at r-project.org
Thu Apr 19 20:17:56 CEST 2007

On Apr 19, 2007, at 10:31 AM, mel wrote:

> Prof Brian Ripley a écrit :
>> You can always link in a wrapper that defined printf and passes  
>> the arguments to Rprintf.
> I apologize but confess i didn't completely understand this  
> suggestion.

The wrapper:

#include <R.h>

int printf(const char *format, ...) {
   va_list (ap);
   va_start(ap, format);
   Rvprintf((char*)format, ap);
   return 0;

If you link this in your project (simply create a separate object  
file with this), the project will be using Rprintf via this wrapper  
instead of printf from libc. Note that you shouldn't be relying on  
the return value literally, otherwise you're in trouble ;).


>> It's documented in 'Writing R Extensions'.
>>   The defines used for compatibility with @Sl{} sometimes causes
>>   conflicts (notably with Windows headers), and the known
>>   problematic defines can be removed by defining @code 
> Yes, i added
> in my cpp code, and the redefinition warning vanishes indeed.
> Many thanks for your precise tips and my apologies for the late  
> answer.
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

More information about the R-devel mailing list