From ripley at stats.ox.ac.uk  Thu Apr 12 17:02:49 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Thu, 12 Apr 2007 16:02:49 +0100 (BST)
Subject: [Rd] printf capture
In-Reply-To: <461E3F8F.4050801@altk.com>
References: <461E02EE.7040105@altk.com>
	<Pine.LNX.4.64.0704121122480.26905@gannet.stats.ox.ac.uk>
	<461E3F8F.4050801@altk.com>
Message-ID: <Pine.LNX.4.64.0704121558260.11792@gannet.stats.ox.ac.uk>

On Thu, 12 Apr 2007, mel wrote:

> Prof Brian Ripley a ?crit :
>
>> If you are using Rgui (it should work under rterm)
>
> yes indeed, it works 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.
>
> Aie ! (I feared this answer). Thanks however for the explanation.
> I was looking at pipe(), scan() etc.
> So, no hope from this side.
>
>> If you have the program, can you not edit it before compiling it?
>> Adding
>> #define printf Rprintf
>> will probably do the trick.
>
> yes thanks, I already though on that, and it works.
> But i would have preferred not touching this 3rd party code.

You can always link in a wrapper that defined printf and passes the 
arguments to Rprintf.

> =====================================
>
> There is another little annoyance (always on WindowsXP + R-2.4.1)
> When including both <windows.h> and <R.h>
> #include <windows.h>
> #include <R.h>
>
> There is a #define ERROR redefinition
>
> #define ERROR ),error(R_problem_buf);} // this one in Rs.h
> #define ERROR 0                        //  in MinGW/.../wingdi.h
>
> It's only a warning, but i would prefer to avoid it
> and i'm searching how to avoid it.
> Thanks for any idea.

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{STRICT_R_HEADERS}.


>
>
> PS : compilation details :
>
> g++ -IJ:/softs/R-2.4.1/include -c f1.cpp -o f1.o
> In file included from J:/softs/R-2.4.1/include/R.h:49,
>                  from f1.cpp:11:
> J:/softs/R-2.4.1/include/R_ext/RS.h:40:1: warning: "ERROR" redefined
> In file included from
> f:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/windows.h:52,
>                  from f1.cpp:10:
> f:/MinGW/bin/../lib/gcc/mingw32/3.4.2/../../../../include/wingdi.h:313:1:
> warning: this is the location of the previous definition
>
> ______________________________________________
> 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


[Rd] printf capture
Prof Brian Ripley