Skip to content

Add tbl_df class to match columns in re_exec() and re_exec_all() #2

@gaborcsardi

Description

@gaborcsardi

From MangoTheCat/rematch2#9

@krlmlr

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     8

@gaborcsardi

Good 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.

@krlmlr

No, but now you can do pos %>% unnest(first) %>% .$match . It's not as concise but avoids the magic of a custom class.

@krlmlr

...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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions