Skip to content
Prev 20309 / 63424 Next

(PR#8777) strsplit does [not] return correct value when spliting ""

Prof Brian Ripley wrote:
[...]
No, the documentation does not explicitely mention this, but shouldn't "there 
are not splits" mean: So the string is returned unchanged?
Consider these examples - I don't think that's the behavior you'd expect 
unless told otherwise:

a <- "a"
b <- ""
a == strsplit (a, ",")	# TRUE
b == strsplit (b, ",")	# FALSE

So, maybe there is a general rule that empty elements get purged?

strsplit ("a,,b", ",")
[[1]]
[1] "a" ""  "b"

strsplit ("a", "a")
[[1]]
[1] ""

Apparently not so. Then why does an empty string get "split" to a non-existent 
string?

Note: I don't really care much about what the behavior is, but if the 
described behavior is indeed intended, I think it should be documented. IMO 
it's pretty counter intuitive.

Regards
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20060417/3f6180dc/attachment.bin