You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running pivot_wider over data where one of the character variables is labelled using the Hmisc::label function, I get the warning message Error: Only bare vectors have shapes.
The Hmisc::label function not only adds a label attribute to the variable, but it changes the variable class to c("labelled", "character").
I found that I could reproduce this error by adding to the class of any variable prior to using pivot_wider. Interestingly, this doesn't occur for factors - so I'm guessing factor variables are treated differently?
I'm not sure if editing the class of a variable is peculiar to Hmisc (and should be corrected there), or whether it should be considered acceptable in general and thus catered for?
## This works
data("fish_encounters")
fish_encounters$fish<- as.character(fish_encounters$fish)
fish_encounters %>% pivot_wider(names_from=station, values_from=seen)
## So does this
data("fish_encounters")
class(fish_encounters$fish) <- c("factor", "extra")
fish_encounters %>% pivot_wider(names_from=station, values_from=seen)
## But these all fail
data("fish_encounters")
fish_encounters$fish<- as.character(fish_encounters$fish)
class(fish_encounters$fish) <- c("character", "extra")
fish_encounters %>% pivot_wider(names_from=station, values_from=seen)
data("fish_encounters")
fish_encounters$station<- as.character(fish_encounters$station)
class(fish_encounters$station) <- c("character", "extra")
fish_encounters %>% pivot_wider(names_from=station, values_from=seen)
data("fish_encounters")
class(fish_encounters$seen) <- c("integer", "extra")
fish_encounters %>% pivot_wider(names_from=station, values_from=seen)
The text was updated successfully, but these errors were encountered:
Could you please rework your reproducible example to use the reprex package ? That makes it easier to see both the input and the output, formatted in such a way that I can easily re-run in a local session.
When running
pivot_wider
over data where one of the character variables is labelled using theHmisc::label
function, I get the warning messageError: Only bare vectors have shapes.
The
Hmisc::label
function not only adds alabel
attribute to the variable, but it changes the variable class toc("labelled", "character")
.I found that I could reproduce this error by adding to the
class
of any variable prior to usingpivot_wider
. Interestingly, this doesn't occur for factors - so I'm guessing factor variables are treated differently?I'm not sure if editing the class of a variable is peculiar to
Hmisc
(and should be corrected there), or whether it should be considered acceptable in general and thus catered for?The text was updated successfully, but these errors were encountered: