I’m trying to print an overview over a dataset’s variable labels using the labelled
-package’s function generate_dictionary()
in a Jupyter Notebook in VS Code, running an R kernel. However, I keep getting error messages such as
ERROR while rich displaying an object: Error in names(res) <- prefix: 'names' attribute [1] must be the same length as the vector [0]
and
ERROR while rich displaying an object: Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 15, 2545, 0, 5, 4, 3
Below I have added a minimal reproducible example which will work in terminal but not in Jupyter Notebook, with the full error output. I could use some help identifying what is causing the problem and if this issue has a solution or is a bug.
df <- data.frame(
a = 1:10,
b = letters[1:10]
)
labelled::var_label(df) <- c("numbers", "letters")
df %>% labelled::generate_dictionary()
ERROR while rich displaying an object: Error in names(res) <- prefix: 'names' attribute [1] must be the same length as the vector [0]
Traceback:
1. tryCatch(withCallingHandlers({
. if (!mime %in% names(repr::mime2repr))
. stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
. rpr <- repr::mime2repr[[mime]](obj)
. if (is.null(rpr))
. return(NULL)
. prepare_content(is.raw(rpr), rpr)
. }, error = error_handler), error = outer_handler)
2. tryCatchList(expr, classes, parentenv, handlers)
3. tryCatchOne(expr, names, parentenv, handlers[[1L]])
4. doTryCatch(return(expr), name, parentenv, handler)
5. withCallingHandlers({
. if (!mime %in% names(repr::mime2repr))
. stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
. rpr <- repr::mime2repr[[mime]](obj)
. if (is.null(rpr))
. return(NULL)
. prepare_content(is.raw(rpr), rpr)
. }, error = error_handler)
6. repr::mime2repr[[mime]](obj)
7. repr_text.data.frame(obj)
8. ellip_limit_arr(obj, rows, cols)
9. arr_parts_format(parts)
10. structure(lapply(parts, arr_part_format), omit = attr(parts,
. "omit"))
11. lapply(parts, arr_part_format)
12. FUN(X[[i]], ...)
13. arr_part_unpack_tbl(part)
14. mapply(tbl_col_format, tbl, names(tbl), SIMPLIFY = FALSE, USE.NAMES = FALSE)
15. (function (col, prefix = "")
. {
. if (is.data.frame(col)) {
. res <- mapply(tbl_col_format, col, names(col), SIMPLIFY = FALSE,
. USE.NAMES = FALSE)
. res <- do.call(cbind.data.frame, res)
. names(res) <- paste0(prefix, "$", names(res))
. return(res)
. }
. else {
. res <- data.frame(col)
. names(res) <- prefix
. return(res)
. }
. })(dots[[1L]][[6L]], dots[[2L]][[6L]])