Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gaborcsardi opened this issue Jun 21, 2017 · 0 comments
Open
Labels
feature a feature request or enhancement

Comments

@gaborcsardi
Copy link
Member

From MangoTheCat#9

@krlmlr

Follow-up to MangoTheCat#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.

@gaborcsardi gaborcsardi added the feature a feature request or enhancement label Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant