[Rd] parse and pushBack (PR#2396)

Mark.Bravington@csiro.au Mark.Bravington@csiro.au
Fri Dec 27 04:18:03 2002


Is this the last bug of the year? Well, it's the last one from me, anyway...

The "parse" function seems to give erratic behaviour when used in
conjunction with "pushBack" on an open connection (R1.6.1, Windows 2000).
Try this: 

> { cat( c( '1', 'a+b', '2'), file='r123.r', sep='\n');
tcon_ file( 'r123.r'); open( tcon); 
print( readLines( tcon, n=1)); 
pushBack( c( 'a+b'), tcon); 
print( parse( file=tcon, n=1));
print( readLines( tcon)); close( tcon); unlink( 'r123.r' }

[1] "1"
Error in parse(file, n, text, prompt) : syntax error on line 1

But if I drop the "pushBack" call, "parse" copes fine with the line a+b in
the file 'r123.r'.

However, "parse" works OK if the line a+b in the file (generated in the call
to "cat") is changed just to contain a, or 1, or "a", or +1. Removing the
"n=1" argument doesn't materially change the behaviour. "readLines" itself
seems to work fine when "pushBack" is used just as above, so "parse" seems
to be the offender here. More possibly helpful diagnostics are given below.

R is the best! Keep up the fantastic work in 2003

cheers
Mark

Interesting behaviour #1: change the line a+b in the file to a; . Parsing is
OK, but the final "readLines" call shows the next line starting ";2". See
also...

...Interesting behaviour #2:

> { tcon_ file( 'r123.r'); open( tcon); print( readLines( tcon, n=1)); 
pushBack( c( '1+', 'c(a)'), tcon); 
print( parse( file=tcon, n=1)); 
print( readLines( tcon)); close( tcon); unlink( 'r123.r') }

[1] "1"
expression(1)
[1] "c(a)" "+2"   "3"   
Warning message: 
incomplete final line found by readLines on `r123.r' 

Look where the plus sign (and semicolon in #1) have been moved to.

*******************************

Mark Bravington
CSIRO (CMIS)
PO Box 1538
Castray Esplanade
Hobart
TAS 7001

phone (61) 3 6232 5118
fax (61) 3 6232 5012
Mark.Bravington@csiro.au 

*******************************

--please do not edit the information below--

Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = 
 major = 1
 minor = 6.1
 year = 2002
 month = 11
 day = 01
 language = R

Windows 2000 Professional (build 2195) Service Pack 2.0

Search Path:
 .GlobalEnv, ROOT, package:handy, package:debug, mvb.session.info,
package:mvbutils, package:tcltk, Autoloads, package:base