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

fix #248 return character vector for Jupyter #251

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions R/S3.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ pander <- function(x = NULL, ...) {
## save current knitr.auto.asis option
kaao <- panderOptions('knitr.auto.asis')

if (isTRUE(panderOptions('knitr.auto.asis')) &&
isTRUE(getOption('knitr.in.progress')) &&
requireNamespace('knitr', quietly = TRUE)) {
if (isTRUE(getOption('jupyter.in_kernel')) |

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?

Copy link
Member Author

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).

(isTRUE(panderOptions('knitr.auto.asis')) &&
isTRUE(getOption('knitr.in.progress')) &&
requireNamespace('knitr', quietly = TRUE))) {

## override knitr.auto.asis option for nested calls
panderOptions('knitr.auto.asis', FALSE)
Expand Down Expand Up @@ -101,7 +102,16 @@ pander <- function(x = NULL, ...) {
stdout <- c(stdout, '')
}

return(knitr::asis_output(paste(stdout, collapse = '\n')))
## collapse character vector into a string
stdout <- paste(stdout, collapse = '\n')

## return string for Jupyter and "asis" output for knitr
if (isTRUE(getOption('jupyter.in_kernel'))) {
return(structure(stdout, class = 'pander_output'))
} else {
return(knitr::asis_output(stdout))
}

})
}

Expand Down