Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tidyr separate error when use sep parenthesis

Tags:

r

tidyr

I cannot separate columns using parenthesis as separation character:

d = data.frame(a = c('af(dsf', 'sdf (asdf', 'sdf(df'))
d %>% separate(a, c('a','b'), sep = '(')

Error in stringi::stri_split_regex(value, sep, n_max) : Incorrectly nested parentheses in regexp pattern. (U_REGEX_MISMATCHED_PAREN)

There is a bug? Thanks in advance.

like image 997
Diego Avatar asked Oct 22 '25 14:10

Diego


1 Answers

We don't need to specify the sep explicitly here as it will automatically detects

separate(d, a, c("a", "b"))
#    a    b
#1  af  dsf
#2 sdf asdf
#3 sdf   df

If needed to specify, either escape (\\() as in the comments or place it in a square bracket

separate(d, a, c("a", "b"), sep="[(]")
#    a    b
#1   af  dsf
#2 sdf  asdf
#3  sdf   df
like image 199
akrun Avatar answered Oct 25 '25 04:10

akrun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!