Skip to content

Commit

Permalink
addin GrabLast()
Browse files Browse the repository at this point in the history
  • Loading branch information
ajrgodfrey committed Sep 3, 2023
1 parent 01eeb94 commit 48fb82b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 17 additions & 2 deletions R/Callback.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 7 additions & 3 deletions man/SessionLog.Rd
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 48fb82b

Please sign in to comment.