[Rd] strsplit (PR#424)

Thomas Lumley thomas@biostat.washington.edu
Tue, 8 Feb 2000 16:26:14 +0000 (GMT)


On Tue, 8 Feb 2000 jlindsey@alpha.luc.ac.be wrote:

> In R.99, when you strsplit with a space (split=" ") as separator and
> the string contains two consecutive spaces, "" is returned.
> 
> strsplit("  "," ")
> returns
> [[1]]
> [1] "" ""
> whereas it used to return character(0)
>   Is this really useful like this?? It certainly messes all my code up. Jim

It is useful like that. It messed up some other people's code, too (eg
mine), but with the previous behaviour there was no way to distinguish
single and double separators. You can now do

	a<-strsplit(vector.of.strings," ")
	b<-lapply(a,function(x) x[x!=""])

to get the old behaviour (and lapply() is now internal C code).

	-thomas


Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._