stri_split: allow omit_empty = NA #107

Closed
gagolews opened this Issue Oct 24, 2014 · 1 comment

Comments

Projects
None yet
1 participant
@gagolews
Owner

gagolews commented Oct 24, 2014

Feature request by @mrdwab in #106 :

vec <- c("A,B,", "", ",C,D", "E,F,G")
stri_split_fixed(vec, ",", simplify = TRUE, omit_empty = NA)
#      [,1] [,2] [,3]
# [1,] "A"  "B"  NA
# [2,] NA   NA   NA  
# [3,] NA   "C"  "D"
# [4,] "E"  "F" "G" 
@gagolews

This comment has been minimized.

Show comment
Hide comment
@gagolews

gagolews Oct 24, 2014

Owner

All right:

> stri_split_fixed(c("ab,c", "d,ef,g", ",h", ""), ",", omit_empty=TRUE, simplify=TRUE)
     [,1] [,2] [,3]
[1,] "ab" "c"  NA  
[2,] "d"  "ef" "g" 
[3,] "h"  NA   NA  
[4,] NA   NA   NA  
> stri_split_fixed(c("ab,c", "d,ef,g", ",h", ""), ",", omit_empty=FALSE, simplify=TRUE)
     [,1] [,2] [,3]
[1,] "ab" "c"  NA  
[2,] "d"  "ef" "g" 
[3,] ""   "h"  NA  
[4,] ""   NA   NA  
> stri_split_fixed(c("ab,c", "d,ef,g", ",h", ""), ",", omit_empty=NA, simplify=TRUE)
     [,1] [,2] [,3]
[1,] "ab" "c"  NA  
[2,] "d"  "ef" "g" 
[3,] NA   "h"  NA  
[4,] NA   NA   NA  
> stri_split_regex(c("ab,c", "d,ef  ,  g", ",  h", ""), "\\p{WHITE_SPACE}*,\\p{WHITE_SPACE}*", omit_empty=NA, simplify=TRUE)
     [,1] [,2] [,3]
[1,] "ab" "c"  NA  
[2,] "d"  "ef" "g" 
[3,] NA   "h"  NA  
[4,] NA   NA   NA  

and

> vec <- c("A,B,", "", ",C,D", "E,F,G")
> stri_split_fixed(vec, ",", simplify = TRUE, omit_empty = NA)
     [,1] [,2] [,3]
[1,] "A"  "B"  NA  
[2,] NA   NA   NA  
[3,] NA   "C"  "D" 
[4,] "E"  "F"  "G" 
Owner

gagolews commented Oct 24, 2014

All right:

> stri_split_fixed(c("ab,c", "d,ef,g", ",h", ""), ",", omit_empty=TRUE, simplify=TRUE)
     [,1] [,2] [,3]
[1,] "ab" "c"  NA  
[2,] "d"  "ef" "g" 
[3,] "h"  NA   NA  
[4,] NA   NA   NA  
> stri_split_fixed(c("ab,c", "d,ef,g", ",h", ""), ",", omit_empty=FALSE, simplify=TRUE)
     [,1] [,2] [,3]
[1,] "ab" "c"  NA  
[2,] "d"  "ef" "g" 
[3,] ""   "h"  NA  
[4,] ""   NA   NA  
> stri_split_fixed(c("ab,c", "d,ef,g", ",h", ""), ",", omit_empty=NA, simplify=TRUE)
     [,1] [,2] [,3]
[1,] "ab" "c"  NA  
[2,] "d"  "ef" "g" 
[3,] NA   "h"  NA  
[4,] NA   NA   NA  
> stri_split_regex(c("ab,c", "d,ef  ,  g", ",  h", ""), "\\p{WHITE_SPACE}*,\\p{WHITE_SPACE}*", omit_empty=NA, simplify=TRUE)
     [,1] [,2] [,3]
[1,] "ab" "c"  NA  
[2,] "d"  "ef" "g" 
[3,] NA   "h"  NA  
[4,] NA   NA   NA  

and

> vec <- c("A,B,", "", ",C,D", "E,F,G")
> stri_split_fixed(vec, ",", simplify = TRUE, omit_empty = NA)
     [,1] [,2] [,3]
[1,] "A"  "B"  NA  
[2,] NA   NA   NA  
[3,] NA   "C"  "D" 
[4,] "E"  "F"  "G" 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment