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() #9

Open
krlmlr opened this issue Feb 1, 2017 · 3 comments
Open

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

krlmlr opened this issue Feb 1, 2017 · 3 comments

Comments

@krlmlr
Copy link

krlmlr commented Feb 1, 2017

Follow-up to #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
Copy link
Contributor

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
Copy link
Author

krlmlr commented Feb 1, 2017

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

@krlmlr
Copy link
Author

krlmlr commented Feb 1, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants