juba / questionr

R package to make surveys processing easier
https://juba.github.io/questionr/
81 stars 17 forks source link

Error in describe for a labelled vector with only NAs #126

Closed larmarange closed 3 years ago

larmarange commented 3 years ago
library(questionr)
library(labelled)

x <- rep(NA_real_, 10)
val_labels(x) <- c(no = 0, yes = 1)

describe(x)
#> Error in idx[[1]]: indice hors limites
describe(unclass(x))
#> Warning in min(x, na.rm = T): aucun argument trouvé pour min ; Inf est renvoyé
#> Warning in max(x, na.rm = T): aucun argument pour max ; -Inf est renvoyé
#> [10 obs.] 
#> numeric: NA NA NA NA NA NA NA NA NA NA
#> min: Inf - max: -Inf - NAs: 10 (100%) - 1 unique values
#> 
#>        n   % val%
#> NA    10 100   NA
#> Total 10 100  100

min(x, na.rm = TRUE)
#> Error in idx[[1]]: indice hors limites
min(unclass(x), na.rm = TRUE)
#> Warning in min(unclass(x), na.rm = TRUE): aucun argument trouvé pour min ; Inf
#> est renvoyé
#> [1] Inf

Created on 2021-01-19 by the reprex package (v0.3.0)

larmarange commented 3 years ago

This is due to the computation of min and max