根据R中的逗号拆分字符串

Split string according to commas in R

我有以下内容:

s <- "abc, xyz, poi (cv, r2, 44, rghj), wer"

我怎样才能拆分它,所以最终结果是:

c("abc", "xyz", "poi (cv, r2, 44, rghj)", "wer")

基本上,strsplit 每个逗号处的字符串,但在括号之外。

尝试

strsplit(s, "\([^)]+\)(*SKIP)(*FAIL)|, ", perl = TRUE)[[1]]
#[1] "abc"                    "xyz" 
#[3] "poi (cv, r2, 44, rghj)" "wer"