From 48fb82b84581c7f6b499e5827b01330241bfaa70 Mon Sep 17 00:00:00 2001 From: ajrgodfrey Date: Mon, 4 Sep 2023 08:27:34 +1200 Subject: [PATCH] addin GrabLast() --- NEWS.md | 2 +- R/Callback.R | 19 +++++++++++++++++-- man/SessionLog.Rd | 10 +++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 79ec5ff0..21ed86c4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ # BrailleR 1.1.0 - added GetPython() to mirror GetPython3(); ditto for GetWxPython() - R Project Sprint 2023 work with Deepayan led to improvement in the ability to extract content of graphics devices; added him as author -- R Project Sprint 2023 work with Gabe led to a working solution to extract recent console output; added him as author +- R Project Sprint 2023 work with Gabe led to a working solution to extract recent console output; added him as author. See SessionLog() and GrabLast() # BrailleR 1.0.2 diff --git a/R/Callback.R b/R/Callback.R index 56a7bc29..8997aa06 100644 --- a/R/Callback.R +++ b/R/Callback.R @@ -1,8 +1,23 @@ # with much help from Gabe Becker BrailleR <- NULL -SessionLog <- function(file = "") { - df <- .get_session_log() + +GrabLast <- function(file = "", n=1) { +.SessionLogWorker(file = file, n=n) +return(invisible(NULL)) +} + +SessionLog <- function(file = "", n=NULL) { +.SessionLogWorker(file = file, n=NULL) +return(invisible(NULL)) +} + +.SessionLogWorker <- function(file = "", n=NULL) { + df <- .get_session_log() +if(!is.null(n)){ +NRows = nrow(df) +df = df[(NRows+1-n): NRows, ] +} mapply(function(expr, pr) cat(c(paste(">", paste(expr, collapse = "\n")), pr, ""), sep = "\n", file = file), expr = df$expr, pr = df$pr_output) diff --git a/man/SessionLog.Rd b/man/SessionLog.Rd index eaf5279f..ba2c6fb0 100644 --- a/man/SessionLog.Rd +++ b/man/SessionLog.Rd @@ -1,16 +1,20 @@ \name{SessionLog} \alias{SessionLog} +\alias{GrabLast} \title{Retrieve a copy of the console input/output} \description{ -Retrieve the output from the last top level call. This function is designed to cater for situaitons wher ehte output scrolls off the screen and is no longer accessible to a screen reader user.} +Retrieve the output from the last n top level calls, or the hole current session. These functions are designed to cater for situations where the output scrolls off the screen and is no longer accessible to a screen reader user.} \usage{ -SessionLog(file = "") +Grablast(file = "", n=1) + +SessionLog(file = "", n=MULL) } \arguments{ \item{file}{a filename; if left unspecified, the output is printed in the console} +\item{n}{the number of calls to retrieve} } \details{ -A stack of top level calls and the resulting output is stored, courtesy of a setting established on package load. This function retrieves elements from that stack.} +A stack of top level calls and the resulting output is stored, courtesy of a setting established on package load. These functions retrieve elements from that stack.} \value{NULL, invisibly; not the output wich is either printed to the console or the file specified} \author{Gabe Becker and some very minor edits from A. Jonathan R. Godfrey}