Skip to content
Prev 131160 / 398502 Next

strsplit on comma, with a trailing comma in input

I have a comma-separated data file in which trailing commas sometimes occur. 
I am using strsplit to extract the data from this file, and it seems great
except in cases with trailing comma characters.

The example below illustrates.  What I'd like is to get a fourth element in
the answer, being an empty string just like the second element.  Is there a
way I can express my patter (or perhaps specify perl or extended) to get
that?
[1] "a" ""  "b"