-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Follow-up to MangoTheCat/rematch2#2. This might even avoid the need for a special $ operator, because from there on you have "proper" nested data frames.
pos <- re_exec_all(notables, name_rex)
# pos <- mutate_each(pos, funs(unclass(lapply(., tibble::as.tibble))), first, last)
pos
## # A tibble: 2 × 4
## first last
## <list> <list>
## 1 <tibble [2 × 3]> <tibble [2 × 3]>
## 2 <tibble [1 × 3]> <tibble [1 × 3]>
## # ... with 2 more variables: .text <chr>, .match <list>
pos$first
## [[1]]
## # A tibble: 2 × 3
## match start end
## <chr> <int> <int>
## 1 Ben 3 5
## 2 Jefferson 20 28
##
## [[2]]
## # A tibble: 1 × 3
## match start end
## <chr> <int> <int>
## 1 Millard 2 8Good idea. I don't think the special $ can be avoided, though. You still cannot write pos$first$match...
I would need a hierarchical data frame, not a data frames embedded into cells of data frames.
No, but now you can do pos %>% unnest(first) %>% .$match . It's not as concise but avoids the magic of a custom class.
...and the equivalent of pos$first$match would be pos$first %>% lapply("[[", "match"), perhaps there's also a purrr verb for this operation.
Anyway, it's not particularly important, I just thought that returning a nested data frame would be more in line with the "tidy regex" description of the package.