-
Notifications
You must be signed in to change notification settings - Fork 16
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
as.character(htmlwidget) gives error in the display system #18
Comments
Not sure what is happening here and that's the biggest problem: the traceback isn't informative :-( |
This is better: obj = as.character(h)
namedlist <- function() setNames(list(), character(0))
data <- namedlist()
for (mime in getOption("jupyter.display_mimetypes")) {
r <- repr:::mime2repr[[mime]](obj)
if (!is.null(r))
data[[mime]] <- r
}
|
heh, i was faster 😉 so you could place a break point somewhere and check what |
class(obj)
"html" "character" Breakpoints in the kernel? How do I do that? IMO there are multiple issues here:
|
and while you’re at it, you could patch repr to do if (!(is.vector(vec) || is.factor(vec)))
stop('expected `vec` to be a vector or factor but it is a', paste(class(vec), collapse = ', ')) instead of |
run or place a |
good idea to be defensive. not without logging a warning to the front end though! we definitely want people to report issues when this happens!
sure, if you have an idea how. R’s error handling is horrible, i’m so happy that it mostly works. (in RStudio it also only mostly works, so we’re in good company)
as said: please let it go to both (but not break output altogether) |
I think the python end does not. Both sides are a pain: in the above case, I really don't care about an error message, but I've also tried to debug non-showing output which happend due to a bug in the display function... Maybe: print an short error to stderr (or whatever we have to do to let it show up as such in the notebook, probably a extra display call for a string) and display the traceback (if that's possible) in the console.
We get much better errors for the evaluated stuff, why does it work there? |
We changed our approach to that in IPython, and IIRC it was in the direction of making the errors from formatters more visible. There was some frustration when previously hidden errors started showing up, but I think that's mostly the right way to go, otherwise people don't see what they expect, but there's no explanation as to why. |
good. that’s always the way i prefer to go: fail early and fail often, don’t put band aids over deeper issues. |
The only thin missing here is why the error in repr_latex is happening... -> why does it get something else than a vector/factor... @flying-sheep do you have an idea why this is happening and wht the proper fix should be? |
BW, this is the new error:
|
there you go. if it was only and that’s good since we don’t want HTML in our LaTeX |
I think the IMO this is another reason for not including |
fixed
who said we’d do that? and would it even do sth.? i thought you need to do
there are no primitive/individual values in R, so we special case length=1 vectors in order not to create e.g. HTML lists for individual values. |
What I mean is that https://github.com/IRkernel/repr/blob/master/R/repr_vector.r should be axed in favour of just return |
what? no. why? |
[personal opinion ahead] Because I see no benefit for rich displaying primitives and it is nearer to the user experience of RStudio users. Oh, and last but not least: I find it prettier :-) [/] |
Is there actually a way to prevent some function to exported/defined? Like I set |
Ok, there is: ca <- structure(1, class = c("C", "A"))
baz <- function(x) UseMethod("baz", x)
baz.A <- function(x) "A"
baz.C <- function(x) {
if (getOption("test", FALSE)){
NextMethod()
} else {
"C"
}
}
options(test = FALSE)
baz(ca)
options(test = TRUE)
baz(ca) |
OK, i find it prettier with rich display, and it’s non-trivial to include the text output into other displays. maybe for HTML/LaTeX escaping it and wrapping it in …nah
no, and i don’t know why primitives should be special-cased here. if we do that, we also would have to make everything else toggleable. and we have to toggle at runtime, in every single function, since options can be changed at runtime if you really want it, you can just override |
No, IMO it's the other way around: we special case data.frames and plots because there a display as a table / image is useful. That's at least the way for the python kernel, which uses |
i find free-form text representations of anything less useful. e.g. are spaces part of the values in the vector or separating them? are those hard line breaks only visual or do they mean something? if just visual, isn’t it better to let a rich display engine handle reflow/soft linebreaking? and as said before: in python, |
Results in
The text was updated successfully, but these errors were encountered: