[Rd] printf capture

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Apr 12 12:28:11 CEST 2007


If you are using Rgui (it should work under rterm) there is no C-level 
'stdout' file stream (the normal state for Windows GUI programs), so no 
way to capture it inside R.

On Thu, 12 Apr 2007, mel wrote:

> printf capture
>
> Dear All,
>
> I'm running R-2.4.1 on WindowsXP.
> I wrote a small C++ DLL using Rprintf() and all works fine
> dyn.load(), is.loaded('f1'), Rprintf(), .C(), all is ok.
>
> Now, the worry :
> I use also a 3rd party piece of C++ program which was not designed
> for R and uses printf().

If you have the program, can you not edit it before compiling it?
Adding

#define printf Rprintf

will probably do the trick.

> I though on sink(...) before .C('f1'), but it doesn't work.
> I call sink(file="res.txt") and only the Rprintf() are catched
>
> Is there any way to however capture those printf() outputs ?
>
> Thanks for any hint/pointer (... and i apologize
> if i missed something obvious !).
>
> Vincent
>
> (for what may be worth, a "minimal" stuff is at www.khi.fr/IB/rp2)
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list