From a721bb191fe7ed3857d9ca086103164d3bf14a91 Mon Sep 17 00:00:00 2001 From: mpadge Date: Wed, 18 Oct 2023 17:18:00 +0200 Subject: [PATCH] evaluate formals in fn calling env to fix #85 --- DESCRIPTION | 2 +- R/function-params.R | 16 ++++++++++++++++ codemeta.json | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 27cf564f..abcb6cc4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: autotest Title: Automatic Package Testing -Version: 0.0.2.201 +Version: 0.0.2.202 Authors@R: c( person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")), diff --git a/R/function-params.R b/R/function-params.R index d5d7d00e..6ff814be 100644 --- a/R/function-params.R +++ b/R/function-params.R @@ -46,6 +46,22 @@ get_params <- function (res, i, this_fn) { pkg_env [[this_fn]] <- tmp_fn } pars <- formals (fun = this_fn, envir = pkg_env) + + # Eval any formals in function environment: + params_env <- as.environment (params) + parent.env (params_env) <- pkg_env + index <- which (vapply ( + pars, + function (i) methods::is (i, "call") && !is.symbol (i), + logical (1) + )) + pars [index] <- lapply (pars [index], function (p) { + res <- p + if (methods::is (p, "call") && !is.symbol (p)) { + res <- eval (p, envir = params_env) + } + }) + nms <- names (pars) pars <- clean_final_pars_list (params, pars, nms) diff --git a/codemeta.json b/codemeta.json index e2ae5ef9..df831045 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/autotest", "issueTracker": "https://github.com/ropensci-review-tools/autotest/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.0.2.201", + "version": "0.0.2.202", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R",