Skip to content

Using complete with a subset of levels silently drops observations #493

@gowerc

Description

@gowerc

Based upon the description of complete its purpose is to add missing observations for specific combinations of variable values. I believe therefore it is not very intuitive for it to silently drop observations if certain levels are not present, for example:

library(tidyr)
library(dplyr)

iris %>% 
    as_data_frame() %>% 
    mutate( Species = as.character(Species)) %>% 
    complete( Species = c("versicolor", "virginica"))

This code silently drops all observations with Species = setosa

I would propose either changing the function to use a full_join() to ensure the original data is preserved or at the very least adding a warning/message so the user is aware that data has been lost.

I am happy to make a PR if people agree this is a beneficial change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementhelp wanted ❤️we'd love your help!pivoting ♻️pivot rectangular data to different "shapes"tidy-dev-day 🤓Tidyverse Developer Day rstd.io/tidy-dev-daywipwork in progress

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions