From ec0909c09131931346c9f0a3346f94f4aab83706 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Tue, 10 May 2016 13:37:08 +0200 Subject: [PATCH 1/2] Add better way to extend base_display The current way overwrites the function in IRkernel, but R CMD check complains about this. So add a way to use the options system to overwrite the function. --- R/display.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/display.R b/R/display.R index d8e42e2..6c52e52 100644 --- a/R/display.R +++ b/R/display.R @@ -2,8 +2,12 @@ #' @importFrom stats setNames namedlist <- function() setNames(list(), character(0)) -base_display <- function(data, metadata) { - warning("IR_display can only be used from the IPython R kernel and R magic.") +base_display <- function(data, metadata = NULL) { + if (is.function(getOption('jupyter.base_display_func'))) { + getOption('jupyter.base_display_func')(data, metadata) + } else { + warning('IR_display can only be used from the IPython R kernel and R magic.') + } } #' Display data by mimetype, with optional alternative representations. From 02c00666fed9f25e35f9ad84edaa6a4c8aa5dc2b Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Tue, 10 May 2016 13:41:01 +0200 Subject: [PATCH 2/2] Make base_diplay depend on a set function in options Should be a bit faster but fails more horrible if a user submits a wrong functions there... --- R/display.R | 6 +----- R/options.r | 6 +++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/display.R b/R/display.R index 6c52e52..9cf2571 100644 --- a/R/display.R +++ b/R/display.R @@ -3,11 +3,7 @@ namedlist <- function() setNames(list(), character(0)) base_display <- function(data, metadata = NULL) { - if (is.function(getOption('jupyter.base_display_func'))) { - getOption('jupyter.base_display_func')(data, metadata) - } else { - warning('IR_display can only be used from the IPython R kernel and R magic.') - } + getOption('jupyter.base_display_func')(data, metadata) } #' Display data by mimetype, with optional alternative representations. diff --git a/R/options.r b/R/options.r index f1c89d9..e50c142 100644 --- a/R/options.r +++ b/R/options.r @@ -12,7 +12,11 @@ opt.defaults <- list( 'application/pdf', 'image/png', 'image/jpeg', - 'image/svg+xml') + '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.') + } + ) .onLoad <- function(libname = NULL, pkgname = NULL) {