R-alpha: bug in scan()

Martyn Plummer (plummer@iarc.fr)
Wed, 27 Nov 1996 15:24:16 +0100


Message-Id: <199611271431.PAA19944@hypatia.math.ethz.ch>
Date: Wed, 27 Nov 1996 15:24:16 +0100
To: r-testers@stat.math.ethz.ch
From: Martyn Plummer <plummer@iarc.fr>
Subject: R-alpha: bug in scan()

When scan is used with the strip.white option, and a non-whitespace
separator, it also strips the last non-whitespace character from
each field. Some examples:

> scan(sep="&",strip.white=TRUE) 
1: > 10&20&30& 
4: >  
Read 3 items 
[1] 1 2 3 
> scan(what=character(),sep="&",strip.white=TRUE) 
1: > cat& dog& mouse & 
4: >  
Read 3 items 
[1] "ca"   "do"   "mous" 

The following patch to scan.c fixes the problem

---cut here---
111,112c111 
< 		*bufp--; 
< 		while( isspace(*bufp--) ) 
--- 
> 		while( isspace(*--bufp) ) 
---cut here---

NB the trailing separator is *not* requied under S-PLUS. The
above examples would produce the following output.

> scan(sep="&",strip.white=T)
1: 10&20&30&
5: 
[1] 10 20 30 NA
> scan(what=character(),sep="&",strip.white=T)
1: cat& dog& mouse &
4: 
5: 
[1] "cat"   "dog"   "mouse" ""     

This is certainly an incompatibility between R and
S-PLUS. Is it a bug or a feature?

Martyn

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-