From 3bd215ce952c672d9d9928a46888b2114f4973c8 Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Tue, 5 Dec 2023 10:34:59 +0100 Subject: [PATCH 1/5] add srcref warning --- NEWS.md | 6 +++++- R/leanify.R | 5 +++++ R/zzz.R | 10 ++++++++++ man/crate.Rd | 4 ++-- man/mlr3misc-package.Rd | 9 +++++++++ 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8b778372..8b627ec8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,8 @@ -# mlr3misc 0.12.0-9000 +# mlr3misc 0.13.0-9000 + +* Warn when the package is installed with source references. + +# mlr3misc 0.13.0 * Updated default environment for `crate()` to `topenv()` (#86). * Added safe methods for dictionary retrieval (#83) diff --git a/R/leanify.R b/R/leanify.R index 9cd6bcf4..c2d65b27 100644 --- a/R/leanify.R +++ b/R/leanify.R @@ -106,3 +106,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") +} diff --git a/R/zzz.R b/R/zzz.R index 5ed2d8fe..99c51b9a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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 are installing 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", + "This warning can be disabled by setting the 'mlr3misc.warn_srcref' option to FALSE.\n")) + } backports::import(pkgname) } # nocov end diff --git a/man/crate.Rd b/man/crate.Rd index 013aa07d..1ff8b164 100644 --- a/man/crate.Rd +++ b/man/crate.Rd @@ -4,7 +4,7 @@ \alias{crate} \title{Isolate a Function from its Environment} \usage{ -crate(.fn, ..., .parent = .GlobalEnv) +crate(.fn, ..., .parent = topenv()) } \arguments{ \item{.fn}{(\verb{function()})\cr @@ -14,7 +14,7 @@ function to crate} The objects, which should be visible inside \code{.fn}.} \item{.parent}{(\code{environment})\cr -Parent environment to look up names. Default so the global environment.} +Parent environment to look up names. Default to \code{\link[=topenv]{topenv()}}.} } \description{ Put a function in a "lean" environment that does not carry unnecessary baggage with it (e.g. references to datasets). diff --git a/man/mlr3misc-package.Rd b/man/mlr3misc-package.Rd index e33bdec1..435875ad 100644 --- a/man/mlr3misc-package.Rd +++ b/man/mlr3misc-package.Rd @@ -10,6 +10,15 @@ Frequently used helper functions and assertions used in 'mlr3' and its companion packages. Comes with helper functions for functional programming, for printing, to work with 'data.table', as well as some generally useful 'R6' classes. This package also supersedes the package 'BBmisc'. } +\section{Package Options}{ + +\itemize{ +\item \code{"mlr3misc.warn_srcref"}: +Disable giving a warning during package loading when packages seem to be installed with the \code{"--with-keep.source"} +option by setting this option to \code{FALSE}. Defaults to \code{TRUE}. +} +} + \seealso{ Useful links: \itemize{ From 09aa351adaf78d0aada4498f91b7bff6131b00ff Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Tue, 5 Dec 2023 10:40:55 +0100 Subject: [PATCH 2/5] ... --- DESCRIPTION | 2 +- NEWS.md | 3 ++- R/zzz.R | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 50a92f4b..9b0121f6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,7 +34,7 @@ Config/testthat/parallel: true Encoding: UTF-8 NeedsCompilation: yes Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.2.3.9000 Collate: 'Dictionary.R' 'named_list.R' diff --git a/NEWS.md b/NEWS.md index 8b627ec8..62a5050c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # mlr3misc 0.13.0-9000 -* Warn when the package is installed with source references. +* Loading `mlr3misc` now gives a warning when the package is being installed + with source references, which can lead to unreasonable memory usage. # mlr3misc 0.13.0 diff --git a/R/zzz.R b/R/zzz.R index 99c51b9a..d918066d 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -15,8 +15,8 @@ .onLoad = function(libname, pkgname) { # nocov start if (has_srcref(ids) && getOption("mlr3misc.warn_srcref", TRUE)) { - warningf(paste0("It looks like you are installing 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", + warningf(paste0("It looks like you are installing 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) From 3dbcba5597e3d98645c280a16f577992c95a0995 Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Tue, 5 Dec 2023 13:08:53 +0100 Subject: [PATCH 3/5] set version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9b0121f6..fcb126d1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "michellang@gmail.com", role = c("cre", "aut"), comment = c(ORCID = "0000-0001-9754-0393")), From 552240a4938eec0e07f40948141d9152673393ab Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Tue, 5 Dec 2023 13:11:43 +0100 Subject: [PATCH 4/5] docs: news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 62a5050c..bec7e949 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ * 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"` # mlr3misc 0.13.0 From 8d5687e9107aee566f251b8a14193723c35476e5 Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Fri, 8 Dec 2023 15:33:49 +0100 Subject: [PATCH 5/5] Update R/zzz.R Co-authored-by: Marc Becker <33069354+be-marc@users.noreply.github.com> --- R/zzz.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index d918066d..367371a5 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -15,7 +15,7 @@ .onLoad = function(libname, pkgname) { # nocov start if (has_srcref(ids) && getOption("mlr3misc.warn_srcref", TRUE)) { - warningf(paste0("It looks like you are installing packages with the '--with-keep.source' flag, which is discouraged.\n", # nolint + 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")) }