Skip to content

Commit

Permalink
Make finalize() methods private
Browse files Browse the repository at this point in the history
As required by newer R6.
  • Loading branch information
gaborcsardi committed Aug 28, 2024
1 parent 6fd231d commit 2dbb6e0
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 122 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1.9000
RoxygenNote: 7.3.2
11 changes: 4 additions & 7 deletions R/r-process.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,15 @@ r_process <- R6::R6Class(
#' @return The return value of the R expression evaluated in the R
#' process.
get_result = function()
rp_get_result(self, private),
rp_get_result(self, private)

#' @description
#' Clean up temporary files once an R process has finished and its
#' handle is garbage collected.
),
private = list(
options = NULL,
finalize = function() {
unlink(private$options$tmp_files, recursive = TRUE)
if ("finalize" %in% ls(super)) super$finalize()
}
),
private = list(
options = NULL
)
)

Expand Down
17 changes: 7 additions & 10 deletions R/r-session.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,6 @@ r_session <- R6::R6Class(
attach = function()
rs_attach(self, private),

#' @description
#' Finalizer that is called when garbage collecting an `r_session`
#' object, to clean up temporary files.
finalize = function() {
unlink(private$tmp_output_file)
unlink(private$tmp_error_file)
unlink(private$options$tmp_files, recursive = TRUE)
if ("finalize" %in% ls(super)) super$finalize()
},

#' @description
#' Print method for an `r_session`.
#' @param ... Arguments are not used currently.
Expand All @@ -225,6 +215,13 @@ r_session <- R6::R6Class(
),

private = list(
finalize = function() {
unlink(private$tmp_output_file)
unlink(private$tmp_error_file)
unlink(private$options$tmp_files, recursive = TRUE)
if ("finalize" %in% ls(super)) super$finalize()
},

options = NULL,
state = NULL,
started_at = NULL,
Expand Down
10 changes: 4 additions & 6 deletions R/rcmd-process.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ rcmd_process <- R6::R6Class(
#' [rcmd_process_options()].
#' @return A new `rcmd_process` object.
initialize = function(options)
rcmdp_init(self, private, super, options),
#' @description
#' Clean up the temporary files created for an `R CMD` process.
rcmdp_init(self, private, super, options)
),
private = list(
options = NULL,
finalize = function() {
unlink(private$options$tmp_files, recursive = TRUE)
if ("finalize" %in% ls(super)) super$finalize()
}
),
private = list(
options = NULL
)
)

Expand Down
10 changes: 4 additions & 6 deletions R/rscript.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,14 @@ rscript_process <- R6::R6Class(
#' @param options A list of options created via
#' [rscript_process_options()].
initialize = function(options)
rscript_init(self, private, super, options),
#' @description Clean up after an `Rscript` process, remove
#' temporary files.
rscript_init(self, private, super, options)
),
private = list(
options = NULL,
finalize = function() {
unlink(private$options$tmp_files, recursive = TRUE)
if ("finalize" %in% ls(super)) super$finalize()
}
),
private = list(
options = NULL
)
)

Expand Down
4 changes: 2 additions & 2 deletions man/r_copycat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 1 addition & 30 deletions man/r_process.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 2 additions & 31 deletions man/r_session.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/r_vanilla.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/rcmd_bg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/rcmd_copycat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions man/rcmd_process.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions man/rscript_process.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2dbb6e0

Please sign in to comment.