Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: warn when installing packages with srcrefs #97

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mlr3misc
Title: Helper Functions for 'mlr3'
Version: 0.12.0-9000
Version: 0.13.0-9000
Authors@R: c(
person("Michel", "Lang", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0001-9754-0393")),
Expand Down
7 changes: 5 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# mlr3misc 0.13.0
# mlr3misc 0.13.0-9000

* Bugfix: disable leanification when `ROXYGEN_PKG` environment variable is set
* Feat: Loading `mlr3misc` now gives a warning when the package is being installed
with source references, which can lead to unreasonable memory usage.
This can be disabled using option `"mlr3misc.warn_srcref"`
* Fix: disable leanification when `ROXYGEN_PKG` environment variable is set

# mlr3misc 0.13.0

Expand Down
5 changes: 5 additions & 0 deletions R/leanify.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,8 @@ leanify_package = function(pkg_env = parent.frame(), skip_if = function(x) FALSE
}
}
}

has_srcref = function(fn) {
# we could also just inspect the attributes but this would evaluate the promise
!identical(as.character(substitute(lines, attr(attr(fn, "srcref"), "srcfile")$original)), "lines")
}
10 changes: 10 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
#' @importFrom R6 R6Class is.R6
#' @importFrom digest digest
#' @importFrom methods formalArgs hasArg
#'
#' @section Package Options:
#' * `"mlr3misc.warn_srcref"`:
#' Disable giving a warning during package loading when packages seem to be installed with the `"--with-keep.source"`
#' option by setting this option to `FALSE`. Defaults to `TRUE`.
"_PACKAGE"

.onLoad = function(libname, pkgname) {
# nocov start
if (has_srcref(ids) && getOption("mlr3misc.warn_srcref", TRUE)) {
warningf(paste0("It looks like you installed packages with the '--with-keep.source' flag, which is discouraged.\n", # nolint
"You can find more information on this on the FAQ section of our website: https://mlr-org.com/faq.html\n",
"This warning can be disabled by setting the 'mlr3misc.warn_srcref' option to FALSE.\n"))
}
backports::import(pkgname)
} # nocov end
9 changes: 9 additions & 0 deletions man/mlr3misc-package.Rd

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