Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while displaying an object (again) #146

Closed
gegnew opened this issue Nov 5, 2021 · 6 comments · Fixed by #151
Closed

Error while displaying an object (again) #146

gegnew opened this issue Nov 5, 2021 · 6 comments · Fixed by #151

Comments

@gegnew
Copy link

gegnew commented Nov 5, 2021

There appears to still be an issue with rich display, a la #97 and #131

a = '[{"something":{"weird":1}}]'
jsonlite::fromJSON(a)

b = '{"something":{"weird":1}}'
jsonlite::fromJSON(b)

Example b works fine. Example a should return some rich version of:

  weird
1     1

but instead gives:

ERROR while rich displaying an object: Error in vapply(part, function(col) {: values must be type 'character',
 but FUN(X[[1]]) result is type 'list'

Traceback:
1. FUN(X[[i]], ...)
2. 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)
3. tryCatchList(expr, classes, parentenv, handlers)
4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
5. doTryCatch(return(expr), name, parentenv, handler)
6. 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)
7. repr::mime2repr[[mime]](obj)
8. repr_text.data.frame(obj)
9. ellip_limit_arr(obj, rows, cols)
10. arr_parts_format(parts)
11. structure(lapply(parts, arr_part_format), omit = attr(parts, 
  .     "omit"))
12. lapply(parts, arr_part_format)
13. FUN(X[[i]], ...)
14. vapply(part, function(col) {
  .     if (is.matrix(col)) 
  .         apply(apply(col, 2L, format), 1L, paste, collapse = ", ")
  .     else format(col)
  . }, character(nrow(part)))
@flying-sheep
Copy link
Member

it really is weird:

'data.frame':	1 obs. of  1 variable:
 $ something:'data.frame':	1 obs. of  1 variable:
  ..$ weird: int 1

@flying-sheep
Copy link
Member

If you tell me how to actually create such an object, I’ll fix it, but …

> str(data.frame(something=data.frame(weird=1)))
'data.frame':	1 obs. of  1 variable:
 $ weird: num 1
> b <- data.frame()
> b$something <- data.frame(weird=1)
> str(b)
Error in `$<-.data.frame`(`*tmp*`, something, value = structure(list(weird = 1), class = "data.frame", row.names = c(NA, : Ersetzung hat 1 Zeile, Daten haben 0
Traceback:

1. `$<-`(`*tmp*`, something, value = structure(list(weird = 1), class = "data.frame", row.names = c(NA, 
 . -1L)))
2. `$<-.data.frame`(`*tmp*`, something, value = structure(list(weird = 1), class = "data.frame", row.names = c(NA, 
 . -1L)))
3. stop(sprintf(ngettext(N, "replacement has %d row, data has %d", 
 .     "replacement has %d rows, data has %d"), N, nrows), domain = NA)

@gegnew
Copy link
Author

gegnew commented Nov 15, 2021

I'm not sure what you mean, didn't I describe above?

a = '[{"something":{"weird":1}}]'
df_that_doesnt_display = jsonlite::fromJSON(a)

df_that_doesnt_display

@flying-sheep
Copy link
Member

Sure, I mean without 3rd party libraries so I can add a test case

@robertour
Copy link

@flying-sheep, I am encountering the same error.

I transformed the example of @gegnew with dput(df_that_doesnt_display):

df_that_doesnt_display = structure(list(something = structure(list(weird = 1L), class = "data.frame", row.names = 1L)), class = "data.frame", row.names = 1L)
df_that_doesnt_display

@flying-sheep, as quick solution you can use print(df_that_doesnt_display)

@flying-sheep
Copy link
Member

Thank you! Added a PR to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants