-
Notifications
You must be signed in to change notification settings - Fork 65
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
fix #248 return character vector for Jupyter #251
base: master
Are you sure you want to change the base?
Conversation
Current coverage is
|
That should work(currently without a Laptop). Will you also add a ’repr_markdown.pander_output(...)’? |
if (isTRUE(panderOptions('knitr.auto.asis')) && | ||
isTRUE(getOption('knitr.in.progress')) && | ||
requireNamespace('knitr', quietly = TRUE)) { | ||
if (isTRUE(getOption('jupyter.in_kernel')) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it’s better to use ||
here, not |
and generally, is this check even necessary or can we just return the structure unconditionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is necessary as pander
does not return anything by design (outside of knitr
or Jupyter).
@JanSchulz, not sure, but my intuition suggests that |
@daroczig It's actually comparable to the knitr return: To make that more clear, your code could now become: pander(x){
if (isTRUE(getOption('knitr.in.progress')) || isTRUE(getOption('jupyter.in_kernel')) {
# Not sure, if there is a reason for the `sink` version....
stdout = capture.output(UseMethod('pander', x))
return return(structure(paste(stdout, collapse="\n"), class = 'pander_output'))
}
UseMethod('pander', x)
}
knit_print.pander_output(x){
if (isTRUE(panderOptions('knitr.auto.asis')){
return(knitr::asis_output(as.character(x)))
} else {
# will call the print.pander_output below
print(x)
}
}
repr_markdown.pander_output(x){
return(as.character(x))
}
print.pander_output(x){
cat(as.character(x))
} It would still ct if not in knitr or the kernel but now the automatic dispatch would do the right thing for the output. |
@JanSchulz as said previously, I refactor might happen on this and
|
yes, that’s great! only a small question: why “pander_output” instead of plain “pander”? do you reserve the generic name for a more fitting class or…? also, actually we don’t have the mission to provide it is perfectly fine to simply put |
@daroczig Sorry, I didn't want to annoy you. I got these knitr things from the documentation at https://cran.r-project.org/web/packages/knitr/vignettes/knit_print.html#for-package-authors in the "For package authors" section. If you add the "return an object", like @flying-sheep I would very much like you to include the small Adding these method in your package, you don't need to import anything, you just have to export these functions. I would also like to ask you to include a |
@JanSchulz no offense taken :) I just won't have much time in the next few months to do major updates on this package. Thanks for the link on the So I thought a similar solution should work within Sorry for the silly question, but before figuring out the optimal next steps in short & long terms, why are you writing and maintaining the code for transforming R objects into HTML, tex or markdown? There's Anyway, probably you have good motives to rewrite those stuff from scratch -- back to my original question that ended up in the above wall of text (sorry for that): can you please describe me the need of |
I think the main reason for this PR is that users using
The problem here is that in the knitr case, you know about the knitr way (e.g, the structure), but knitr does not need to know about the pander way. If we have to implement a
Here it's more a problem that there could be other character vectors (from other methods or simple a The way we currently handle "output" goes like this: For all output objects (
Thats a good question and I actually think it makes sense to use pander/xtable for things like data frames and matrix: IRkernel/repr#35
I'm not sure if the users wants that: having a table nicely styled is something differently than having a table for summary output. E.g. currently it's as far as I undertsand pander a explicit step to get a table in knitpy and not the plain text outputfor a summary (e.g. If we owuld want that, we could use it like: out <- repr_markdown(input)
if (repr_markdown(out) == NULL){
out = pander(input)
} This would only work if pander in that mode would return We could also use your definitions, like
But this makes IMO only sense for the main types (up to matrix/data.frame). -> IRkernel/repr#35 To give you a bit of background how repr is used: the jupyter R notebook (or actually every jupyter frontend) wants output in multiple formats: plain text ( It would actually be nice to merge knitrs and our approach, but currently we can't:
So the idea is it to unify these two approaches by making repr useable in knitr and ask for repr to be included in the |
No description provided.