From p.dalgaard at biostat.ku.dk  Thu Apr 12 14:21:43 2007
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Thu, 12 Apr 2007 14:21:43 +0200
Subject: [Rd] printf capture
In-Reply-To: <Pine.LNX.4.64.0704121122480.26905@gannet.stats.ox.ac.uk>
References: <461E02EE.7040105@altk.com>
	<Pine.LNX.4.64.0704121122480.26905@gannet.stats.ox.ac.uk>
Message-ID: <461E2457.9040401@biostat.ku.dk>

Prof Brian Ripley wrote:
> 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.
>
>   
If not:

If it really is a standalone program, look into variations of system() 
and shell().

If it is a DLL, you might get away with explicitly opening a file 
descriptor for stdout on entry and closing it on exit. Not sure exactly 
how this works, though, especially on Windows.
>> 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
>>
>>     
>
>



[Rd] printf capture
Peter Dalgaard