David Sterratt
2012-May-11 21:36 UTC
[Rd] Replacements for stdout and stderr guaranteed to be open in all versions of R
I maintain the geometry package, which integrates the Qhull C library (http://qhull.org) into R. The Qhull function I hook into requires an open FILE handle as one of its arguments. I had set this file handle to stdout, but now R check NOTEs the presence of stdout, and the CRAN maintainers asked me to get rid of these NOTEs. Including the following defines means the checks are passed on CRAN: #ifdef WIN32 extern FILE * R_Consolefile; extern FILE * R_Outputfile; #else #include <Rinterface.h> #fi #undef stderr #define stderr R_Consolefile #undef stdout #define stdout R_Outputfile However, this does not work on Rgui.exe, when the above leads to a crash. Looking at http://svn.r-project.org/R/trunk/src/gnuwin32/system.c it would appear that R_Consolefile and R_Outputfile only point to open files when CharacterMode == RTerm, not in GUI mode. Therefore my question is, are there any replacements for stdout and stderr that work across all versions of R? All the best, David. -- David C Sterratt, Research Fellow. Tel: (+44) 131 651 1739 Institute for Adaptive and Neural Computation School of Informatics, University of Edinburgh Informatics Forum, 10 Crichton Street, Edinburgh EH8 9AB, Scotland, UK
Duncan Murdoch
2012-May-11 22:36 UTC
[Rd] Replacements for stdout and stderr guaranteed to be open in all versions of R
On 12-05-11 5:36 PM, David Sterratt wrote:> I maintain the geometry package, which integrates the Qhull C library > (http://qhull.org) into R. The Qhull function I hook into requires an > open FILE handle as one of its arguments. I had set this file handle to > stdout, but now R check NOTEs the presence of stdout, and the CRAN > maintainers asked me to get rid of these NOTEs. > > Including the following defines means the checks are passed on CRAN: > > #ifdef WIN32 > extern FILE * R_Consolefile; > extern FILE * R_Outputfile; > #else > #include<Rinterface.h> > #fi > #undef stderr > #define stderr R_Consolefile > #undef stdout > #define stdout R_Outputfile > > However, this does not work on Rgui.exe, when the above leads to a > crash. Looking at > http://svn.r-project.org/R/trunk/src/gnuwin32/system.c > it would appear that R_Consolefile and R_Outputfile only point to open > files when CharacterMode == RTerm, not in GUI mode. > > Therefore my question is, are there any replacements for stdout and > stderr that work across all versions of R?I'm pretty sure the answer is "no". What you can do is have your initialization code open a new handle (pointing to something that is not stdout, e.g. a file), and then pass that to the Qhull function. Duncan Murdoch