juliasilge / tidytext

Text mining using tidy tools :sparkles::page_facing_up::sparkles:
https://juliasilge.github.io/tidytext/
Other
1.18k stars 182 forks source link

Please upgrade tidytext to tidyeval so dplyr 0.7.* rlang parametrics will work #74

Closed dan-reznik closed 6 years ago

dan-reznik commented 7 years ago

loads required libraries

library(tidyverse)
library(tidytext)

creates to 2-row tibble, test simple operation (it works)

df <- tribble(~id,~descr,1,"hello bug",2,"goodbye bug")
df %>% select(id,descr) %>% unnest_tokens(word,descr)

A tibble: 4 x 2 id word

1 1 hello 2 1 bug 3 2 goodbye 4 2 bug

creates a parametrized dplyr 0.7.* version of the above

myFn <- function(df, col1,col2) {
  col1 <- enquo(col1)
  col2 <- enquo(col2)
  df %>%  select(!!col1, !!col2) %>% # works
    unnest_tokens(word, !!col2) # this won't work
}

Call to myFn below pukes at unnest_tokens()

myFn(df,id,descr)

Error: Invalid column specification

juliasilge commented 7 years ago

Related to #67

dan-reznik commented 7 years ago

Julia I don't think it's related to that other Issue which is about non-standard column names. In my case it's related to non-compatibility with the latest dplyr 0.7.* capabilities for creating parametric functions.

I had originally posted this Issue on the dplyr github page but the author told me the issue was that tidytext is still not a tidyeval library.

Does that make sense?

juliasilge commented 7 years ago

Yep, makes sense! I'm pretty sure both issues will be solved by adding tidyeval to our package.

dan-reznik commented 7 years ago

That's great! Any chance this could be done soonish...

juliasilge commented 7 years ago

Probably not this weekend but it is a priority.

juliasilge commented 7 years ago

We now have support for rlang/tidyeval in tidytext!

library(tidyverse)
library(tidytext)

df <- tribble(~id,~descr,1,"hello bug",2,"goodbye bug")

myFn <- function(df, col1,col2) {
  col1 <- enquo(col1)
  col2 <- enquo(col2)
  df %>%  
    select(!!col1, !!col2) %>% 
    unnest_tokens(word, !!col2) 
}

myFn(df, id, descr)
#> # A tibble: 4 x 2
#>      id    word
#>   <dbl>   <chr>
#> 1     1   hello
#> 2     1     bug
#> 3     2 goodbye
#> 4     2     bug

Thanks for using our package; let me know if you run into any problems with implementing tidyeval solutions with it.

juliasilge commented 7 years ago

I'm reopening this as a reminder to myself to update the rest of tidytext's functions.

dan-reznik commented 7 years ago

thank you julia! looking fwd to using it

dan

On Mon, Sep 4, 2017 at 5:23 PM, Julia Silge notifications@github.com wrote:

We now have support for rlang/tidyeval in tidytext!

library(tidyverse) library(tidytext) df <- tribble(~id,~descr,1,"hello bug",2,"goodbye bug") myFn <- function(df, col1,col2) { col1 <- enquo(col1) col2 <- enquo(col2) df %>% select(!!col1, !!col2) %>% # works unnest_tokens(word, !!col2) # this won't work }

myFn(df, id, descr)#> # A tibble: 4 x 2#> id word#> #> 1 1 hello#> 2 1 bug#> 3 2 goodbye#> 4 2 bug

Thanks for using our package; let me know if you run into any problems with implementing tidyeval solutions with it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/juliasilge/tidytext/issues/74#issuecomment-327024067, or mute the thread https://github.com/notifications/unsubscribe-auth/APeqlvADT969lm5GHpkgmjnBtz3rrK1Jks5sfFxKgaJpZM4OfTE3 .

github-actions[bot] commented 2 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.