Skip to content

pivot_wider handles NAs inconsistently with tidyr #1238

Closed
@carlganz

Description

@carlganz

When there are NA's in the names_from variable dbplyr translates pivot_wider inconsistently.

library(dplyr)
library(dbplyr)
library(tidyr)

### need to setup your own SQL Server connection
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
x <- tibble(
  id = "id",
  x = 1:3,
  y = c("A", NA, "B")
)
copy_to(con, x, overwrite = T)
x2 <- tbl(con, "x")

# NA's work properly in-memory this returns 2
x %>%
  pivot_wider(names_from = y, values_from = x) %>%
  pull(`NA`)

# with dbplyr this returns NA
x2 %>%
  pivot_wider(names_from = y, values_from = x) %>%
  pull(`NA`)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions