Running examples in ‘sjlabelled-Ex.R’ failed
The error most likely occurred in:

> ### Name: as_character
> ### Title: Convert variable into factor with associated value labels
> ### Aliases: as_character as_character.data.frame as_label
> ###   as_label.data.frame
> 
> ### ** Examples
> 
> data(efc)
> print(get_labels(efc)['c161sex'])
$c161sex
[1] "Male"   "Female"

> head(efc$c161sex)
[1] 2 2 1 1 2 1
> head(as_label(efc$c161sex))
[1] Female Female Male   Male   Female Male  
Levels: Male Female
> 
> print(get_labels(efc)['e42dep'])
$e42dep
[1] "independent"          "slightly dependent"   "moderately dependent"
[4] "severely dependent"  

> table(efc$e42dep)

  1   2   3   4 
 66 225 306 304 
> table(as_label(efc$e42dep))

         independent   slightly dependent moderately dependent 
                  66                  225                  306 
  severely dependent 
                 304 
> 
> head(efc$e42dep)
[1] 3 3 3 4 4 4
> head(as_label(efc$e42dep))
[1] moderately dependent moderately dependent moderately dependent
[4] severely dependent   severely dependent   severely dependent  
4 Levels: independent slightly dependent ... severely dependent
> 
> # structure of numeric values won't be changed
> # by this function, it only applies to labelled vectors
> # (typically categorical or factor variables)
> 
> str(efc$e17age)
 num [1:908] 83 88 82 67 84 85 74 87 79 83 ...
 - attr(*, "label")= chr "elder' age"
> str(as_label(efc$e17age))
 num [1:908] 83 88 82 67 84 85 74 87 79 83 ...
 - attr(*, "label")= chr "elder' age"
> 
> 
> # factor with non-numeric levels
> as_label(factor(c("a", "b", "c")))
[1] a b c
Levels: a b c
> 
> # factor with non-numeric levels, prefixed
> x <- factor(c("a", "b", "c"))
> x <- set_labels(x, labels = c("ape", "bear", "cat"))
> as_label(x, prefix = TRUE)
[1] [a] ape  [b] bear [c] cat 
Levels: [a] ape [b] bear [c] cat
> 
> 
> # create vector
> x <- c(1, 2, 3, 2, 4, NA)
> # add less labels than values
> x <- set_labels(
+   x,
+   labels = c("yes", "maybe", "no"),
+   force.labels = FALSE,
+   force.values = FALSE
+ )
"x" has more values than "labels", hence not all values are labelled.
> 
> # convert to label w/o non-labelled values
> as_label(x)
[1] yes   maybe no    maybe <NA>  <NA> 
Levels: yes maybe no
> 
> # convert to label, including non-labelled values
> as_label(x, add.non.labelled = TRUE)
[1] yes   maybe no    maybe 4     <NA> 
Levels: yes maybe no 4
> 
> 
> # create labelled integer, with missing flag
> if (require("haven")) {
+   x <- labelled(
+     c(1:3, tagged_na("a", "c", "z"), 4:1, 2:3),
+     c("Agreement" = 1, "Disagreement" = 4, "First" = tagged_na("c"),
+       "Refused" = tagged_na("a"), "Not home" = tagged_na("z"))
+   )
+ 
+   # to labelled factor, with missing labels
+   as_label(x, drop.na = FALSE)
+ 
+   # to labelled factor, missings removed
+   as_label(x, drop.na = TRUE)
+ 
+   # keep missings, and use non-labelled values as well
+   as_label(x, add.non.labelled = TRUE, drop.na = FALSE)
+ }
Loading required package: haven

Attaching package: ‘haven’

The following objects are masked from ‘package:sjlabelled’:

    as_factor, read_sas, read_spss, read_stata, write_sas, zap_labels

Error: Can't convert <character> to <labelled<double>>.
Backtrace:
     █
  1. ├─sjlabelled::as_label(x, drop.na = FALSE)
  2. ├─sjlabelled:::as_label.default(x, drop.na = FALSE)
  3. │ └─sjlabelled:::as_label_helper(...)
  4. │   ├─base::`[<-`(...)
  5. │   └─vctrs:::`[<-.vctrs_vctr`(...)
  6. │     └─vctrs::vec_cast(value, x)
  7. ├─vctrs::vec_default_cast(...)
  8. │ └─vctrs:::vctr_cast(x, to, x_arg = x_arg, to_arg = to_arg)
  9. │   └─vctrs::vec_restore(x, to)
 10. ├─vctrs:::vec_restore_dispatch(x = x, to = to, n = n)
 11. └─vctrs:::vec_restore.vctrs_vctr(x = x, to = to, n = n)
 12.   └─vctrs::stop_incompatible_cast(x, to, x_arg = "", to_arg = "")
 13.     └─vctrs::stop_incompatible_type(...)
 14.       └─vctrs:::stop_incompatible(...)
 15.         └─vctrs:::stop_vctrs(...)
Execution halted