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/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)
diff --git a/R/display.r b/R/display.r
index 00ce8eb..e6a7def 100644
--- a/R/display.r
+++ b/R/display.r
@@ -1,9 +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.
#'
#' @seealso \code{\link{prepare_mimebundle}}
#'
@@ -11,13 +14,26 @@
#' publish_mimebundle(list('text/html' = '
Hi!
'))
#' publish_mimebundle(
#' list('image/svg+xml' = ''),
-#' list('image/svg+xml' = list(width = 100, height = 100)))}
+#' 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) {
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.
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) {
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}.
+}
}
}
diff --git a/man/publish_mimebundle.Rd b/man/publish_mimebundle.Rd
index 499c684..d46f90e 100644
--- a/man/publish_mimebundle.Rd
+++ b/man/publish_mimebundle.Rd
@@ -2,24 +2,43 @@
% 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})}
\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})
+\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{
+\item \code{clear_output}: Clear the output from the current cell.
+}}
+
\examples{
\dontrun{## (Run inside of an IRkernel)
publish_mimebundle(list('text/html' = '