diff --git a/NEWS.md b/NEWS.md index aceb1f5..d65af17 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # evaluate (development version) +* `evalute(include_timing)` has been deprecated. I can't find any use of it on GitHub, and it adds substantial code complexity for little gain. * `watchout()` is no longer exported; it's really an implementation detail that should never have been leaked to the public interface. * `evaluate()` gains an output class (`evaluate_evaluation`/`list`) and a basic print method. * `evaluate()` now correctly captures plots created before messages/warnings/errors (#28). diff --git a/R/eval.R b/R/eval.R index e3f1ef0..1c6321a 100644 --- a/R/eval.R +++ b/R/eval.R @@ -35,10 +35,7 @@ #' processes the output from the evaluation. The default simply prints the #' visible return values. #' @param filename string overrriding the [base::srcfile()] filename. -#' @param include_timing if `TRUE`, evaluate will wrap each input -#' expression in `system.time()`, which will be accessed by following -#' `replay()` call to produce timing information for each evaluated -#' command. +#' @param include_timing Deprecated. #' @import graphics grDevices utils evaluate <- function(input, envir = parent.frame(), @@ -56,6 +53,10 @@ evaluate <- function(input, stop_on_error <- as.integer(stop_on_error) stopifnot(length(stop_on_error) == 1) + if (isTRUE(include_timing)) { + warning("`evaluate(include_timing)` is deprecated") + } + parsed <- parse_all(input, filename, stop_on_error != 2L) if (inherits(err <- attr(parsed, 'PARSE_ERROR'), 'error')) { source <- new_source(parsed$src, expression(), output_handler$source) @@ -91,8 +92,7 @@ evaluate <- function(input, keep_warning = keep_warning, keep_message = keep_message, log_warning = log_warning, - output_handler = output_handler, - include_timing = include_timing + output_handler = output_handler ) watcher$check_devices() @@ -120,8 +120,7 @@ evaluate_top_level_expression <- function(exprs, keep_warning = TRUE, keep_message = TRUE, log_warning = FALSE, - output_handler = new_output_handler(), - include_timing = FALSE) { + output_handler = new_output_handler()) { stopifnot(is.expression(exprs)) source <- new_source(src, exprs[[1]], output_handler$source) @@ -190,11 +189,6 @@ evaluate_top_level_expression <- function(exprs, } else { handle <- force } - if (include_timing) { - timing_fn <- function(x) system.time(x)[1:3] - } else { - timing_fn <- function(x) {x; NULL} - } user_handlers <- output_handler$calling_handlers evaluate_handlers <- list(error = eHandler, warning = wHandler, message = mHandler) @@ -202,18 +196,13 @@ evaluate_top_level_expression <- function(exprs, handlers <- c(user_handlers, evaluate_handlers) for (expr in exprs) { - srcindex <- length(output) - time <- timing_fn( - ev <- handle( - with_handlers( - withVisible(eval(expr, envir)), - handlers - ) + ev <- handle( + with_handlers( + withVisible(eval(expr, envir)), + handlers ) ) handle_output(TRUE) - if (!is.null(time)) - attr(output[[srcindex]]$src, 'timing') <- time if (show_value(output_handler, ev$visible)) { # Ideally we'd evaluate the print() generic in envir in order to find diff --git a/R/replay.R b/R/replay.R index d431e61..a22e265 100644 --- a/R/replay.R +++ b/R/replay.R @@ -41,8 +41,7 @@ replay.character <- function(x) { #' @export replay.source <- function(x) { - s <- if (is.null(attr(x$src,'timing'))) '' else render_timing(attr(x$src, 'timing')) - cat(paste0(s, line_prompt(x$src))) + cat(line_prompt(x$src)) } #' @export @@ -70,38 +69,6 @@ replay.recordedplot <- function(x) { print(x) } -render_timing <- function(t) { - if (max(t) < 0.5) '' else paste0( - '[', render_sec(t[[1]] + t[[2]]), # User time + Kernel time - ',', render_sec(t[[3]]), # Wall time - ']' - ) -} - -render_sec <- function(s) { - if (s < 0.005) return('<5ms') - if (s < 1) return(paste0(round(s,2), 's')) - if (s < 10) return(paste0(round(s,1), 's')) - sec <- round(s,0) - if (sec < 120) return(paste0(sec, 's')) - min <- floor(sec/60) - sec <- sec - min*60 - if (min < 10) return(paste0( - min, 'm', formatC(sec, digits = 0, width = 2, format = "f", flag = "0"), 's' - )) - min <- min + round(sec/60, 0) - if (min < 120) return(paste0(min, 'm')) - h <- floor(min/60) - min <- min - h * 60 - if (h < 48) return(paste0( - h, 'h', formatC(min, digits = 0, width = 2, format = "f", flag = "0"), 'm' - )) - d <- floor(h/24) - h <- h - d*24 - return(paste0(d, 'd', h, 'h')) -} - - format_condition <- function(x) { if (inherits(x, "rlang_warning") || inherits(x, "rlang_error")) { format(x) diff --git a/man/evaluate.Rd b/man/evaluate.Rd index ba35886..9093d1a 100644 --- a/man/evaluate.Rd +++ b/man/evaluate.Rd @@ -58,10 +58,7 @@ visible return values.} \item{filename}{string overrriding the \code{\link[base:srcfile]{base::srcfile()}} filename.} -\item{include_timing}{if \code{TRUE}, evaluate will wrap each input -expression in \code{system.time()}, which will be accessed by following -\code{replay()} call to produce timing information for each evaluated -command.} +\item{include_timing}{Deprecated.} } \description{ Compare to \code{\link[=eval]{eval()}}, \code{evaluate} captures all of the