From Martin Maechler <maechler@stat.math.ethz.ch>  Sat Oct  4 16:49:15 1997
From: Martin Maechler <maechler@stat.math.ethz.ch> (Martin Maechler)
Date: Sat, 4 Oct 1997 17:49:15 +0200
Subject: R-alpha: paste problem in TASKS --- yes, I do really want it
Message-ID: <199710041549.RAA01183@sophie.ethz.ch>

This is from line 104 of current TASKS:

----------------------------------------------------------------------
TASK:	"paste" problem
STATUS:	Open
FROM:	maechler@stat.math.ethz.ch
	in S,
		paste(....., collapse = string)
	always returns ONE string  (a character vector of length 1),
	according to documentation and several examples.
	in R, this is not true:
		R> paste(rep(" ",0), collapse="...") #anything for collapse
		character(0)
		S> paste(rep(" ",0), collapse="...") #anything for collapse
		[1] ""
	Again, I think	R  is more logical than S here, but it was decided
	that in minor cases, compatibility comes first...
	[ Low priority.	 Complain if you really need it. ]
			 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
			 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I hereby complain .

Yes I do want it.  The current behaviour results in  code being broken 
which would work otherwise.
{{of course I can always fix that code by an extra if(....) else .....
  but the point is that if  parse(..) behaved more reasonable,
  I did not have to fix that code..
}}

Yet another example is the  `fun()' Example in  ?tempfile
[in the latest snapshot of R-0.60]
which terminates on error for me just because of the above bug:

fun <- function() {
  FILE <- tempfile("fun")
  on.exit(unlink(FILE))
  system(paste("printenv >", FILE))
  x <- strsplit(scan(FILE, what = ""), "=")
  v <- n <- character(LEN <- length(x))
  for (i in 1:LEN) {
    n[i] <- x[[i]][1]
    v[i] <- paste(x[[i]][-1], collapse = "=")
  }
  structure(v, names = n)
}

> fun()
Read 83 items
Error in "[<-"(c("/u/sfs/adm", "/usr/local/bin", ".:/u/maechler/bib:/u/maechler/tex/styles:.:/u/sfs/bib",  : nothing to replace with

--- and the reason is:    x[[i]][-1]  is empty (some environment values are
					        just defined with no value ..)
 in which case 
		 paste(x[[i]][-1], collapse = "=")
 returns 
		 character(0)

 where it rather should return (IMHO)  
	
		 ""

 v[i] <- character(0)  then gives the error, whereas
 v[i] <- ""		would exactly produce what is wanted.

-----
Martin
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


R-alpha: paste problem in TASKS --- yes, I do really want it
Martin Maechler