Skip to content

Commit

Permalink
Merge branch 'main' into callr_rng
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc committed Feb 9, 2024
2 parents 78b2e12 + c48fb32 commit 201d6ec
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
^\.github$
^\.lintr$
^docs$
^cran-comments\.md$
^CRAN-SUBMISSION$
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mlr3misc
Title: Helper Functions for 'mlr3'
Version: 0.13.0-9000
Version: 0.14.0.9000
Authors@R: c(
person("Michel", "Lang", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0001-9754-0393")),
Expand Down Expand Up @@ -34,7 +34,7 @@ Config/testthat/parallel: true
Encoding: UTF-8
NeedsCompilation: yes
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3.9000
RoxygenNote: 7.3.1
Collate:
'Dictionary.R'
'named_list.R'
Expand Down Expand Up @@ -97,6 +97,7 @@ Collate:
'str_collapse.R'
'str_indent.R'
'str_trunc.R'
'strip_srcrefs.R'
'to_decimal.R'
'topo_sort.R'
'transpose.R'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ S3method(remove_named,data.frame)
S3method(remove_named,data.table)
S3method(remove_named,default)
S3method(remove_named,environment)
S3method(strip_srcrefs,"function")
S3method(strip_srcrefs,default)
export("%nin%")
export("get_private<-")
export(Callback)
Expand Down Expand Up @@ -156,6 +158,7 @@ export(stopf)
export(str_collapse)
export(str_indent)
export(str_trunc)
export(strip_srcrefs)
export(to_decimal)
export(topo_sort)
export(transpose_list)
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# mlr3misc 0.13.0-9000
# mlr3misc (development version)

* Feat: Added `strip_screfs` S3 generic, which removes source references from objects

# mlr3misc 0.14.0

* Added argument `.compile` to function `crate()` because R disables byte-code
compilation of functions when changing their enclosing environment
Expand Down
29 changes: 29 additions & 0 deletions R/strip_srcrefs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#' @title Strip source references from objects
#'
#' @description
#' Source references can make objects unexpectedly large and are undesireable in many situations.
#' As {renv} installs packages with the `--with-keep.source` option, we sometimes need to remove source references
#' from objects.
#' Methods should remove source references from the input, but should otherwise leave the input unchanged.
#'
#' @param x (any)\cr
#' The object to strip of source references.
#' @param ... (any)\cr
#' Additional arguments to the method.
#'
#' @keywords internal
#' @export
strip_srcrefs = function(x, ...) {
UseMethod("strip_srcrefs")
}

#' @export
strip_srcrefs.default = function(x, ...) {
x
}

#' @export
strip_srcrefs.function = function(x, ...) {
attr(x, "srcref") = NULL
x
}
2 changes: 1 addition & 1 deletion man/calculate_hash.Rd

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

22 changes: 22 additions & 0 deletions man/strip_srcrefs.Rd

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

6 changes: 6 additions & 0 deletions tests/testthat/test_strip_srcrefs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("remove srcref from function", {
f = function(x) NULL
attr(f, "srcref") = "mock_srcrefs"
f_strip = strip_srcrefs(f)
expect_true(is.null(attr(f_strip, "srcref")))
})

0 comments on commit 201d6ec

Please sign in to comment.