-
Notifications
You must be signed in to change notification settings - Fork 420
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorwipwork in progresswork in progress
Description
complete() has behavior advertised as follows:
For factors, the full set of levels (not just those that appear in the data) are used.
However, this seems to only be the case so long as you have at least one record. A few workarounds are less than optimal in my opinion, and it would be quite helpful for this functionality to work with an empty data.frame
options <- factor(c('a','b','c'))
df <- data.frame(column=character(), column2=character())
levels(df$column) <- options; levels(df$column2) <- options;
## Does not work - though I would expect it to
df %>% complete(column, column2)
## Works - nice if you have options readily available
df %>% complete(column=options, column2=options)
## Works - based on factors, and a bit tedious
df %>% complete(column=factor(levels(column),levels=levels(column)),column2=factor(levels(column),levels=levels(column)))
## With data, things work fine:
df <- data.frame(column=c('a'),column2=c('b'))
levels(df$column) <- options; levels(df$column2) <- options;
## Does not work above - works here
df %>% complete(column, column2)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorwipwork in progresswork in progress