From e2ba8f52a43124d84e4393e6824a56a0de8f5b16 Mon Sep 17 00:00:00 2001 From: bburns632 Date: Wed, 10 Apr 2024 21:56:50 -0500 Subject: [PATCH] extend to do.call case with func param as text (resolves #302) (#309) --- NEWS.md | 1 + R/FunctionReporter.R | 8 ++++++++ inst/baseballstats/R/batting_statistics.R | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index f9f093ee..c4151749 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # pkgnet (dev) ## NEW FEATURES +* `do.call` with the function argument as string will now properly appear on the function reporter. Previously, this would show as a `do.call` node with a circular reference. (#302) ## CHANGES diff --git a/R/FunctionReporter.R b/R/FunctionReporter.R index 4c911c92..d8ca0c3e 100644 --- a/R/FunctionReporter.R +++ b/R/FunctionReporter.R @@ -407,6 +407,14 @@ FunctionReporter <- R6::R6Class( if (listable){ + + # If do.call and first argument is string (atomic), covert to call + if (length(x) >= 2){ + if (deparse(x[[1]]) == "do.call" & is.character(x[[2]])){ + x[[2]] <- parse(text=x[[2]]) + } + } + # Filter out atomic values because we don't care about them x <- Filter(f = Negate(is.atomic), x = x) diff --git a/inst/baseballstats/R/batting_statistics.R b/inst/baseballstats/R/batting_statistics.R index 33fd8405..e1a14d26 100644 --- a/inst/baseballstats/R/batting_statistics.R +++ b/inst/baseballstats/R/batting_statistics.R @@ -77,7 +77,8 @@ slugging_avg <- function(outcomes){ 4 * sum(outcomes == 'hr') } - return(bases_on_hits / at_bats(outcomes)) + denom <- do.call("at_bats", outcomes) + return(bases_on_hits / denom) }