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

Unable to use names_glue within pivot_wider() when NA is the only unique value #394

Closed
camnesia opened this issue Oct 14, 2022 · 1 comment · Fixed by #395
Closed

Unable to use names_glue within pivot_wider() when NA is the only unique value #394

camnesia opened this issue Oct 14, 2022 · 1 comment · Fixed by #395
Labels
bug an unexpected problem or unintended behavior

Comments

@camnesia
Copy link

Unable to use names_glue within pivot_wider() when the only unique value is NA - the same code does not cause any problems when lazy_dt() is not used.

example <- fish_encounters %>%
  mutate(test = NA_integer_) %>%
  lazy_dt() %>%
  pivot_wider(., 
              names_glue = "{test}",
              names_from = test, 
              values_from = seen,
              names_repair = 'minimal') %>%
  collect()

image

names_glue does work, if there are other values available in names (for example using the station variable). Using a variable with only NA does seem to be possible but only if names_glue is not used at all.

example <- fish_encounters %>%
  mutate(test = NA_integer_) %>%
  lazy_dt() %>%
  pivot_wider(., 
              names_glue = "{station}",
              names_from = station, 
              values_from = seen,
              names_repair = 'minimal') %>%
  collect()
@markfairbanks markfairbanks added the bug an unexpected problem or unintended behavior label Oct 14, 2022
@markfairbanks
Copy link
Collaborator

Thanks for catching this - we'll take a look.

Smaller reprex:

library(dtplyr)
library(dplyr)
library(tidyr)

df <- tibble(x = c("a", "a"), y = c("a", NA), z = 1:2)

df %>%
  lazy_dt() %>%
  pivot_wider(names_from = y,
              values_from = z,
              names_glue = "{y}",
              names_repair = "minimal") %>%
  collect()
#> Error: NA in 'new' at positions [1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants