From 69fef4e01db3d0af9a9a5a59ceb69c8606034715 Mon Sep 17 00:00:00 2001 From: Randy Lai Date: Sat, 10 Sep 2016 15:26:32 -0400 Subject: [PATCH] bind last output to .Last.value --- R/execution.r | 1 + R/utils.r | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/R/execution.r b/R/execution.r index 27f3030b..42421612 100644 --- a/R/execution.r +++ b/R/execution.r @@ -168,6 +168,7 @@ handle_value = function(obj) { page(mimebundle) } else { log_debug('Sending display_data: %s', paste(capture.output(str(mimebundle$data)), collapse = '\n')) + set_last_value(obj) send_response('display_data', current_request, 'iopub', mimebundle) } }, diff --git a/R/utils.r b/R/utils.r index befac874..305f7398 100644 --- a/R/utils.r +++ b/R/utils.r @@ -29,3 +29,9 @@ fromRawJSON <- function(r) { Encoding(s) <- 'UTF-8' fromJSON(s) } + +set_last_value <- function(obj) { + unlockBinding(".Last.value", .BaseNamespaceEnv) + assign(".Last.value", obj, .BaseNamespaceEnv) + lockBinding(".Last.value", .BaseNamespaceEnv) +}