Skip to content

Commit

Permalink
move the on.exit() call earlier so I don't have to rely on the argume…
Browse files Browse the repository at this point in the history
…nt after = FALSE, which is not available before R 3.5
  • Loading branch information
yihui committed Aug 1, 2024
1 parent 7e91cf3 commit 3db4e99
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions R/fuse.R
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,14 @@ fuse = function(input, output = NULL, text = NULL, envir = parent.frame(), quiet
if (!is.null(output_base <- output_path(input, output)))
output_base = sans_ext(output_base)

opts = reactor()
# clean up the figure folder on exit if it's empty
on.exit(xfun::del_empty_dir({
if (dir.exists(fig.dir <- opts$fig.path)) fig.dir else dirname(fig.dir)
}), add = TRUE)

# restore and clean up some objects on exit
opts = reactor(); opts2 = as.list(opts); on.exit(reactor(opts2), add = TRUE)
opts2 = as.list(opts); on.exit(reactor(opts2), add = TRUE)
oenv = as.list(.env); on.exit(reset_env(oenv, .env), add = TRUE)

# set working directory if unset
Expand Down Expand Up @@ -449,10 +455,6 @@ fuse = function(input, output = NULL, text = NULL, envir = parent.frame(), quiet
opts[[name]] = p
}
set_path('fig.path'); set_path('cache.path')
# clean up the figure folder on exit if it's empty
on.exit(xfun::del_empty_dir({
if (dir.exists(fig.dir <- opts$fig.path)) fig.dir else dirname(fig.dir)
}), add = TRUE, after = FALSE)

.env$input = input
res = .fuse(blocks, input, quiet)
Expand Down

0 comments on commit 3db4e99

Please sign in to comment.