@@ -232,55 +232,61 @@ with_progress <- function(expr, handlers = progressr::handlers(), cleanup = TRUE
232232
233233 # # Evaluate expression
234234 capture_conditions <- TRUE
235- withCallingHandlers(
236- expr ,
237- progression = function (p ) {
238- # # Don't capture conditions that are produced by progression handlers
239- capture_conditions <<- FALSE
240- on.exit(capture_conditions <<- TRUE )
235+ res <- withVisible(
236+ withCallingHandlers(
237+ expr ,
238+ progression = function (p ) {
239+ # # Don't capture conditions that are produced by progression handlers
240+ capture_conditions <<- FALSE
241+ on.exit(capture_conditions <<- TRUE )
241242
242- # # Any buffered output to flush?
243- if (flush_terminal ) {
244- if (length(conditions ) > 0L || has_buffered_stdout(stdout_file )) {
245- calling_handler(control_progression(" hide" ))
246- stdout_file <<- flush_stdout(stdout_file , close = FALSE )
247- conditions <<- flush_conditions(conditions )
248- calling_handler(control_progression(" unhide" ))
243+ # # Any buffered output to flush?
244+ if (flush_terminal ) {
245+ if (length(conditions ) > 0L || has_buffered_stdout(stdout_file )) {
246+ calling_handler(control_progression(" hide" ))
247+ stdout_file <<- flush_stdout(stdout_file , close = FALSE )
248+ conditions <<- flush_conditions(conditions )
249+ calling_handler(control_progression(" unhide" ))
250+ }
249251 }
250- }
251-
252- calling_handler( p )
253- },
254- condition = function ( c ) {
255- if ( ! capture_conditions || inherits(c , c( " progression " , " error " ))) return ()
256- if (inherits( c , delay_conditions )) {
257- # # Record
258- conditions [[length( conditions ) + 1L ]] <<- c
259- # # Muffle
260- if (inherits( c , " message " )) {
261- invokeRestart( " muffleMessage " )
262- } else if (inherits( c , " warning " )) {
263- invokeRestart( " muffleWarning " )
264- } else if (inherits( c , " condition " )) {
265- # # If there is a "muffle" restart for this condition,
266- # # then invoke that restart, i.e. "muffle" the condition
267- restarts <- computeRestarts( c )
268- for ( restart in restarts ) {
269- name <- restart $ name
270- if (is.null( name )) next
271- if ( ! grepl( " ^muffle " , name )) next
272- invokeRestart( restart )
273- break
252+
253+ calling_handler( p )
254+ },
255+ condition = function ( c ) {
256+ if ( ! capture_conditions || inherits( c , c( " progression " , " error " ))) return ()
257+ if ( inherits(c , delay_conditions )) {
258+ # # Record
259+ conditions [[length( conditions ) + 1L ]] <<- c
260+ # # Muffle
261+ if (inherits( c , " message " )) {
262+ invokeRestart( " muffleMessage " )
263+ } else if (inherits( c , " warning " )) {
264+ invokeRestart( " muffleWarning " )
265+ } else if (inherits( c , " condition " )) {
266+ # # If there is a "muffle" restart for this condition,
267+ # # then invoke that restart, i.e. "muffle" the condition
268+ restarts <- computeRestarts( c )
269+ for ( restart in restarts ) {
270+ name <- restart $ name
271+ if (is.null( name )) next
272+ if (! grepl( " ^muffle " , name )) next
273+ invokeRestart( restart )
274+ break
275+ }
274276 }
275277 }
276278 }
277- }
279+ )
278280 )
279-
281+
280282 # # Success
281283 status <- " ok"
282-
283- invisible (NULL )
284+
285+ if (res $ visible ) {
286+ res $ value
287+ } else {
288+ invisible (res $ value )
289+ }
284290}
285291
286292
0 commit comments