[R] Capturing errors [not buffered output] from Rterm

Keith Jewell k.jewell at campden.co.uk
Thu Jun 10 15:43:51 CEST 2010


Thanks to both Prof. Ripley and Duncan Murdoch for correctly diagnosing my 
problem as failure to redirect stderr (nothing to do with buffering).

Both pointed me to R CMD BATCH which would have done the job, if I hadn't 
wanted to run interactively - in my real task (not the example below) I had 
Rterm --ess. I guess I could use R CMD BATCH  --ess but instead I'm using 
the suggestion in rw-FAQ Q2.12 of simply adding 2>&1 to redirect stderr to 
stdout.

Rterm   < m:\test.rsc > m:\test.log 2>&1

Problem solved. The answer was in rw-FAQ , mea culpa for not spotting it 
myself, thanks for treating me kindly!

"Prof Brian Ripley" <ripley at stats.ox.ac.uk> wrote in message 
news:alpine.LFD.2.00.1006101333520.25202 at gannet.stats.ox.ac.uk...
> On Thu, 10 Jun 2010, Keith Jewell wrote:
>
>> In MS Windows I
>>  a) invoke Rterm from a batch file (test.bat)
>>  b) to execute commands from a script (m:\test.rsc)
>>  c) capturing output in a log file (m:\test.log)
>>
>> BUT if the script results in an error the error message is NOT written to
>> the log file, leaving me problems when the error is from a complicated
>> function.
>
> Sure, warning and errors are written to stderr, which you did not 
> redirect.  This is covered in rw-FAQ Q2.12.  Using R CMD BATCH would have 
> done this for you ....
>
> This is not to do with 'buffered output': in any case R uses minimal 
> buffering so stdout and stderr can be mixed nicely on a single log file.
>
>> Simplified example:.
>>
>> test.bat ------------------------
>> REM ensure 'R' is in path
>> path \\Server02\stats\R\R-Current\bin\;%PATH%
>> Rterm  --no-init-file --no-restore-data --no-save --silent < m:\test.rsc 
>>  >
>> m:\test.log
>> ---------------------
>>
>> m:\test.rsc -----------------
>> print("this is a test")
>> #generate an error
>> nls()
>> ------------------
>>
>> The error message:
>>  "Error in .Internal(inherits(x, what, which)) : 'x' is missing"
>> is is NOT written to the log file, which just ends
>>
>> m:\test.log --------------------------
>>  <snip>
>>> print("this is a test")
>> [1] "this is a test"
>>> #generate an error
>>> nls()
>> ---------------------
>>
>> I surmise this is due to output buffering (?). In an S-Plus version I 
>> turned
>> off buffering with
>>  guiSetOption(option.name="BufferOutputWindows", value.string="F")
>> but I don't think this is available in R (?).
>>
>> Has anyone any suggestions?
>>
>> Thanks in advance,
>>
>> Keith Jewell
>> --please do not edit the information below--
>>
>> R Version:
>> platform = i386-pc-mingw32
>> arch = i386
>> os = mingw32
>> system = i386, mingw32
>> status =
>> major = 2
>> minor = 11.0
>> year = 2010
>> month = 04
>> day = 22
>> svn rev = 51801
>> language = R
>> version.string = R version 2.11.0 (2010-04-22)
>>
>> Windows Server 2003 x64 (build 3790) Service Pack 2
>>
>> Locale:
>> LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
>> Kingdom.1252;LC_MONETARY=English_United
>> Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252
>>
>> Search Path:
>> .GlobalEnv, package:datasets, CBRIForecast, package:RODBC, package:tree,
>> package:locfit, package:lattice, package:akima, package:nlme, 
>> package:MASS,
>> package:grDevices, package:geometry, KJRutils, package:xlsReadWrite,
>> package:svSocket, package:TinnR, package:R2HTML, package:Hmisc,
>> package:survival, package:splines, package:graphics, package:stats,
>> CBRIutils, package:utils, package:tcltk, package:tools, package:methods,
>> TempEnv, Autoloads, package:base
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> -- 
> 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-help mailing list