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

expand.(): Cannot yet handle negatives #282

Closed
arthur-albuquerque opened this issue Jun 19, 2021 · 6 comments · Fixed by #283
Closed

expand.(): Cannot yet handle negatives #282

arthur-albuquerque opened this issue Jun 19, 2021 · 6 comments · Fixed by #283
Labels
bug Something isn't working

Comments

@arthur-albuquerque
Copy link

Hi, tidytable has changed the way I wrangle my data.

Unfortunately, I'm having issues using expand.() probably because my vector contains negative values.

"expand.(nesting(a3,b3,sig3),log_pred_mass = seq(-20,20,0.2))
Error in fsort(x, decreasing = decreasing, na.last = na.last) :
Cannot yet handle negatives."

Do you have any idea when it will handle negative values?

Thank you!

@markfairbanks
Copy link
Owner

Interesting - I didn't know that data.table::fsort() couldn't handle negatives.

Should be a relatively easy fix - I'll switch over to using base::sort(x, method = "radix"). It's a fast sort that data.table contributed to base R, but it also works on negative values.

@arthur-albuquerque
Copy link
Author

That would be great. Thanks!

@markfairbanks
Copy link
Owner

markfairbanks commented Jun 20, 2021

reprex

pacman::p_load(tidytable)

test_df <- tidytable(x = c(1, 1, 2), y = c(1, 1, 2))

test_df %>%
  expand.(nesting.(x, y), z = c(-1.0, 1.0))
#> Error in fsort(x, decreasing = decreasing, na.last = na.last): Cannot yet handle negatives.

@markfairbanks markfairbanks added the bug Something isn't working label Jun 20, 2021
@markfairbanks
Copy link
Owner

Also I noticed in your example above you were using tidyr::nesting() instead of tidytable::nesting.(). Though it works, your code will run faster if you use the tidytable version:

pacman::p_load(tidytable, tidyverse)

data_size <- 1000000
test_df <- tidytable(
  x = sample(1:100, data_size, TRUE),
  y = sample(letters, data_size, TRUE)
)

bench::mark(
  tidytable_nesting = test_df %>% expand.(nesting.(x, y)),
  tidyr_nesting = test_df %>% expand.(nesting(x, y))
) %>%
  select.(expression, median)
#> # A tidytable: 2 × 2
#>   expression          median
#>   <bch:expr>        <bch:tm>
#> 1 tidytable_nesting   8.77ms
#> 2 tidyr_nesting      22.58ms

@arthur-albuquerque
Copy link
Author

Oh wow, I didn't notice that! Great tip.

@markfairbanks
Copy link
Owner

Fixed! Thanks for catching this 👍

I'll submit the new version of tidytable to CRAN in the next few days so it will be fixed there as well.

library(tidytable)

test_df <- tidytable(x = c(1, 1, 2), y = c(1, 1, 2))

test_df %>%
  expand.(nesting.(x, y), z = c(-1.0, 1.0))
#> # A tidytable: 4 × 3
#>       x     y     z
#>   <dbl> <dbl> <dbl>
#> 1     1     1    -1
#> 2     1     1     1
#> 3     2     2    -1
#> 4     2     2     1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants