I've been trying to split a space delimited string with double-quotes in R
for some time but without success. An example of a string is as follows:

/rainfall snowfall "Channel storage" "Rivulet storage"/

It's important for us because these are column headings that must match the
subsequent data. 

Here is some code I've been trying:

str <- 'rainfall snowfall "Channel storage" "Rivulet storage"'
regex <- "[^\\s\"']+|\"([^\"]*)\""
split <- strsplit(str, regex, perl=T)
what I would like is

[1] "rainfall" "snowfall" "Channel storage" "Rivulet storage"

but what I get is:

[1] ""  " " " " " "

The vector is the right length (which is encouraging) but of course the
strings are empty or contain a single space. Any suggestions?

Thanks in advance!



--
View this message in context: 
http://r.789695.n4.nabble.com/splitting-a-string-by-space-except-when-contained-within-quotes-tp4651286.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to