From d67d3bc1bd3bc7e6e04e7fc7808168faba3e4dd4 Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Thu, 29 Jul 2021 17:47:13 -0700 Subject: [PATCH 1/9] Add a clear_output function to IRdisplay Fixes https://github.com/IRkernel/IRkernel/issues/432 --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index 394adc6..05f010f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(clear_output) export(display) export(display_html) export(display_javascript) From 0b9da524cbf5fb9f56e61e9fef55376100b81625 Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Thu, 29 Jul 2021 17:48:50 -0700 Subject: [PATCH 2/9] Update IRdisplay-options.Rd --- man/IRdisplay-options.Rd | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/man/IRdisplay-options.Rd b/man/IRdisplay-options.Rd index df31f93..add55c9 100644 --- a/man/IRdisplay-options.Rd +++ b/man/IRdisplay-options.Rd @@ -1,12 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/options.r \docType{data} -\name{irdisplay_option_defaults} -\alias{irdisplay_option_defaults} +\name{IRdisplay-options} \alias{IRdisplay-options} +\alias{irdisplay_option_defaults} \title{IRdisplay options} \format{ -An object of class \code{list} of length 2. +An object of class \code{list} of length 3. } \usage{ irdisplay_option_defaults @@ -28,6 +28,10 @@ and the function they use to display them. Has the signature \code{function(data, metadata = NULL)}. Per default emits a \code{\link{warning}}, and is set when running an \code{IRkernel}. } +\item{\code{jupyter.clear_output_func}}{ + Function used by \code{\link{clear_output}}. Has the signature \code{function(wait = TRUE)}. + Per default emits a \code{\link{warning}}, and is set when running an \code{IRkernel}. +} } } From aad7abba9a21d3f9dcde74119ba0fb8f6bee7e77 Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Thu, 29 Jul 2021 17:49:25 -0700 Subject: [PATCH 3/9] Update publish_mimebundle.Rd --- man/publish_mimebundle.Rd | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/man/publish_mimebundle.Rd b/man/publish_mimebundle.Rd index 499c684..395a578 100644 --- a/man/publish_mimebundle.Rd +++ b/man/publish_mimebundle.Rd @@ -2,9 +2,12 @@ % Please edit documentation in R/display.r \name{publish_mimebundle} \alias{publish_mimebundle} +\alias{clear_output} \title{Display data by mimetype, with optional alternative representations.} \usage{ publish_mimebundle(data, metadata = NULL) + +clear_output(wait = TRUE) } \arguments{ \item{data}{A named list mapping mimetypes to content (\code{\link[base]{character}} or \code{\link[base]{raw} vectors})} @@ -14,6 +17,11 @@ publish_mimebundle(data, metadata = NULL) \description{ Calls the function stored as option value of \code{jupyter.base_display_func}. (see: \link{IRdisplay-options}) } +\section{Functions}{ +\itemize{ +\item \code{clear_output}: Clear the output from the current cell. +}} + \examples{ \dontrun{## (Run inside of an IRkernel) publish_mimebundle(list('text/html' = '

Hi!

')) From 03433478dee216bd71b08d2dade76c880e811108 Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Thu, 29 Jul 2021 17:50:15 -0700 Subject: [PATCH 4/9] Add a clear_output() function --- R/display.r | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/display.r b/R/display.r index 00ce8eb..40a7129 100644 --- a/R/display.r +++ b/R/display.r @@ -18,6 +18,12 @@ publish_mimebundle <- function(data, metadata = NULL) { getOption('jupyter.base_display_func')(data, metadata) } +#' @describeIn publish_mimebundle Clear the output from the current cell. +#' @export +clear_output <- function(wait = TRUE) { + getOption('jupyter.clear_output_func')(wait) +} + #' Create and use multiple available reprs #' #' Both functions create a mimebundle for multiple reprs. From 0d4246bdcde7ac90b7045106d79438ba6ba8abf0 Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Thu, 29 Jul 2021 17:51:17 -0700 Subject: [PATCH 5/9] Update options for new clear_output_func --- R/options.r | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/R/options.r b/R/options.r index 2cea6d1..1d2a7c8 100644 --- a/R/options.r +++ b/R/options.r @@ -15,11 +15,14 @@ #' Has the signature \code{function(data, metadata = NULL)}. #' Per default emits a \code{\link{warning}}, and is set when running an \code{IRkernel}. #' } -#' +#' \item{\code{jupyter.clear_output_func}}{ +#' Function used by \code{\link{clear_output}}. Has the signature \code{function(wait = TRUE)}. +#' Per default emits a \code{\link{warning}}, and is set when running an \code{IRkernel}. #' } -#' -#' @rdname IRdisplay-options -#' @aliases IRdisplay-options +#' +#' } +#' +#' @name IRdisplay-options #' @export irdisplay_option_defaults <- list( jupyter.display_mimetypes = c( @@ -27,22 +30,25 @@ irdisplay_option_defaults <- list( 'text/html', 'text/markdown', 'text/latex', - + 'application/json', 'application/javascript', - + 'application/geo+json', 'application/vdom.v1+json', 'application/vnd.plotly.v1+json', 'application/vnd.vegalite.v2+json', 'application/vnd.vega.v4+json', - + 'application/pdf', 'image/png', 'image/jpeg', 'image/svg+xml'), jupyter.base_display_func = function(data, metadata = NULL) { warning('IRdisplay can only be used from the IPython R kernel and R magic.') + }, + jupyter.clear_output_func = function(wait = TRUE) { + warning('IRdisplay can only be used from the IPython R kernel and R magic.') }) .onLoad <- function(libname = NULL, pkgname = NULL) { From 34289ab16be986fc637f99f670e678aabf3173b2 Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Tue, 3 Aug 2021 11:49:22 -0700 Subject: [PATCH 6/9] Document wait in clear_output --- R/display.r | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/display.r b/R/display.r index 40a7129..06988c2 100644 --- a/R/display.r +++ b/R/display.r @@ -4,6 +4,8 @@ #' #' @param data A named list mapping mimetypes to content (\code{\link[base]{character}} or \code{\link[base]{raw} vectors}) #' @param metadata A named list mapping mimetypes to named lists of metadata, e.g. \code{list('image/png' = list(width = 5))} +#' @param wait Wait to clear the output until new output is available. Default \code{TRUE}. If \code{FALSE}, clears the existing output immediately +#' before the new output is displayed. #' #' @seealso \code{\link{prepare_mimebundle}} #' From 9c4718712d05f7942ff8fbc600ca1d592768c0d5 Mon Sep 17 00:00:00 2001 From: Michael Quinn Date: Tue, 3 Aug 2021 11:50:48 -0700 Subject: [PATCH 7/9] Update publish_mimebundle.Rd --- man/publish_mimebundle.Rd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/man/publish_mimebundle.Rd b/man/publish_mimebundle.Rd index 395a578..70b7607 100644 --- a/man/publish_mimebundle.Rd +++ b/man/publish_mimebundle.Rd @@ -13,6 +13,8 @@ clear_output(wait = TRUE) \item{data}{A named list mapping mimetypes to content (\code{\link[base]{character}} or \code{\link[base]{raw} vectors})} \item{metadata}{A named list mapping mimetypes to named lists of metadata, e.g. \code{list('image/png' = list(width = 5))}} + +\item{wait}{Wait to clear the output until new output is available. Default \code{TRUE}. If \code{FALSE}, clears the existing output immediately before the new output is displayed.} } \description{ Calls the function stored as option value of \code{jupyter.base_display_func}. (see: \link{IRdisplay-options}) From 931574a04c8ddd3a8d48892288039629e854d3b8 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Tue, 4 Jan 2022 08:58:21 +0100 Subject: [PATCH 8/9] Improve docs --- DESCRIPTION | 2 +- R/display.r | 8 +++++--- man/publish_mimebundle.Rd | 7 +++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 831504a..d32430a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,4 +20,4 @@ Imports: repr License: MIT + file LICENSE Encoding: UTF-8 -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 diff --git a/R/display.r b/R/display.r index 06988c2..aae168f 100644 --- a/R/display.r +++ b/R/display.r @@ -1,11 +1,12 @@ #' Display data by mimetype, with optional alternative representations. #' -#' Calls the function stored as option value of \code{jupyter.base_display_func}. (see: \link{IRdisplay-options}) +#' \code{publish_mimebundle} calls the function stored as option value of \code{jupyter.base_display_func}, +#' \code{clear_output} calls the value of option \code{jupyter.clear_output_func}. (see: \link{IRdisplay-options}) #' #' @param data A named list mapping mimetypes to content (\code{\link[base]{character}} or \code{\link[base]{raw} vectors}) #' @param metadata A named list mapping mimetypes to named lists of metadata, e.g. \code{list('image/png' = list(width = 5))} -#' @param wait Wait to clear the output until new output is available. Default \code{TRUE}. If \code{FALSE}, clears the existing output immediately -#' before the new output is displayed. +#' @param wait Wait to clear the output until new output is available. Default \code{TRUE}. +#' If \code{FALSE}, clears the existing output immediately before the new output is displayed. #' #' @seealso \code{\link{prepare_mimebundle}} #' @@ -14,6 +15,7 @@ #' publish_mimebundle( #' list('image/svg+xml' = ''), #' list('image/svg+xml' = list(width = 100, height = 100)))} +#' clear_output() #' #' @export publish_mimebundle <- function(data, metadata = NULL) { diff --git a/man/publish_mimebundle.Rd b/man/publish_mimebundle.Rd index 70b7607..b3c2c03 100644 --- a/man/publish_mimebundle.Rd +++ b/man/publish_mimebundle.Rd @@ -14,10 +14,12 @@ clear_output(wait = TRUE) \item{metadata}{A named list mapping mimetypes to named lists of metadata, e.g. \code{list('image/png' = list(width = 5))}} -\item{wait}{Wait to clear the output until new output is available. Default \code{TRUE}. If \code{FALSE}, clears the existing output immediately before the new output is displayed.} +\item{wait}{Wait to clear the output until new output is available. Default \code{TRUE}. +If \code{FALSE}, clears the existing output immediately before the new output is displayed.} } \description{ -Calls the function stored as option value of \code{jupyter.base_display_func}. (see: \link{IRdisplay-options}) +\code{publish_mimebundle} calls the function stored as option value of \code{jupyter.base_display_func}, +\code{clear_output} calls the value of option \code{jupyter.clear_output_func}. (see: \link{IRdisplay-options}) } \section{Functions}{ \itemize{ @@ -30,6 +32,7 @@ publish_mimebundle(list('text/html' = '

Hi!

')) publish_mimebundle( list('image/svg+xml' = ''), list('image/svg+xml' = list(width = 100, height = 100)))} +clear_output() } \seealso{ From 600c7ea2d4003d1a15de894c0719d40f61860b77 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Tue, 4 Jan 2022 09:15:15 +0100 Subject: [PATCH 9/9] more docs --- R/display.r | 10 ++++++++-- man/publish_mimebundle.Rd | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/R/display.r b/R/display.r index aae168f..e6a7def 100644 --- a/R/display.r +++ b/R/display.r @@ -14,8 +14,14 @@ #' publish_mimebundle(list('text/html' = '

Hi!

')) #' publish_mimebundle( #' list('image/svg+xml' = ''), -#' list('image/svg+xml' = list(width = 100, height = 100)))} -#' clear_output() +#' list('image/svg+xml' = list(width = 100, height = 100))) +#' +#' for (i in 1:5) { +#' Sys.sleep(.2) # simulate work +#' clear_output() # clear previous iteration +#' cat(i) # alternative: IRdisplay::display(i) +#' flush.console() # make output available +#' }} #' #' @export publish_mimebundle <- function(data, metadata = NULL) { diff --git a/man/publish_mimebundle.Rd b/man/publish_mimebundle.Rd index b3c2c03..d46f90e 100644 --- a/man/publish_mimebundle.Rd +++ b/man/publish_mimebundle.Rd @@ -31,8 +31,14 @@ If \code{FALSE}, clears the existing output immediately before the new output is publish_mimebundle(list('text/html' = '

Hi!

')) publish_mimebundle( list('image/svg+xml' = ''), - list('image/svg+xml' = list(width = 100, height = 100)))} -clear_output() + list('image/svg+xml' = list(width = 100, height = 100))) + +for (i in 1:5) { + Sys.sleep(.2) # simulate work + clear_output() # clear previous iteration + cat(i) # alternative: IRdisplay::display(i) + flush.console() # make output available +}} } \seealso{