diff --git a/share/jupyter/kernels/xr/resources/execute.R b/share/jupyter/kernels/xr/resources/execute.R index 484e32d..26e2fb9 100644 --- a/share/jupyter/kernels/xr/resources/execute.R +++ b/share/jupyter/kernels/xr/resources/execute.R @@ -28,6 +28,7 @@ handle_error <- function(e) { } handle_value <- function(execution_counter) function(obj, visible) { + set_last_value(obj) if (!visible) return() # only doing text-plain for now diff --git a/share/jupyter/kernels/xr/resources/routines.R b/share/jupyter/kernels/xr/resources/routines.R index 4d57a75..57ad3cd 100644 --- a/share/jupyter/kernels/xr/resources/routines.R +++ b/share/jupyter/kernels/xr/resources/routines.R @@ -12,5 +12,5 @@ publish_stream <- function(name, text) { } display_data <- function(data = NULL, metadata = NULL) { - .Call("xeusr_display_data", jsonlite::toJSON(data), jsonlite::toJSON(metadata), PACKAGE = "(embedding)") + invisible(.Call("xeusr_display_data", jsonlite::toJSON(data), jsonlite::toJSON(metadata), PACKAGE = "(embedding)")) } diff --git a/share/jupyter/kernels/xr/resources/setup.R b/share/jupyter/kernels/xr/resources/setup.R index 3781436..143832f 100644 --- a/share/jupyter/kernels/xr/resources/setup.R +++ b/share/jupyter/kernels/xr/resources/setup.R @@ -17,7 +17,7 @@ local({ "..", "share", "jupyter", "kernels", "xr", "resources" ) - files <- setdiff(list.files(here), "setup.R") + files <- setdiff(list.files(here), c("setup.R", "routines.R")) xeus_env$.xeus_call <- function(fn, ...) { get(fn, envir = xeus_private_env)(...) @@ -26,5 +26,6 @@ local({ for (f in files) { sys.source(file.path(here, f), envir = xeus_private_env) } + sys.source(file.path(here, "routines.R"), envir = xeus_env) }) diff --git a/share/jupyter/kernels/xr/resources/utils.R b/share/jupyter/kernels/xr/resources/utils.R index 0f62440..8cee32f 100644 --- a/share/jupyter/kernels/xr/resources/utils.R +++ b/share/jupyter/kernels/xr/resources/utils.R @@ -10,6 +10,12 @@ namedlist <- function() { `names<-`(list(), character()) } +set_last_value <- function(obj) { + unlockBinding(".Last.value", .BaseNamespaceEnv) + assign(".Last.value", obj, .BaseNamespaceEnv) + lockBinding(".Last.value", .BaseNamespaceEnv) +} + # borrowed from IRkernel plot_builds_upon <- function(prev, current) { if (is.null(prev)) {