From 17151a5fcca613f109ff5440462bd052f248e597 Mon Sep 17 00:00:00 2001 From: Joshua Ulrich Date: Mon, 25 Sep 2023 11:28:02 -0500 Subject: [PATCH] Fix if-statement when deparsed FUN length is > 1 The if-statement would error if `FUN = function(x) mean(x)` because deparse(substitute(FUN)) has more than one element. --- R/period.apply.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/period.apply.R b/R/period.apply.R index 34defd23..031ca44d 100644 --- a/R/period.apply.R +++ b/R/period.apply.R @@ -45,7 +45,7 @@ function(caller) `period.apply` <- function(x, INDEX, FUN, ...) { - if (deparse(substitute(FUN)) == "mean") { + if (deparse(substitute(FUN))[1] == "mean") { .mean_by_column_message("period.apply") } x <- try.xts(x, error = FALSE) @@ -101,7 +101,7 @@ function (x, INDEX, FUN, ...) `apply.daily` <- function(x,FUN, ...) { - if (deparse(substitute(FUN)) == "mean") { + if (deparse(substitute(FUN))[1] == "mean") { .mean_by_column_message("apply.daily") } ep <- endpoints(x,'days') @@ -110,7 +110,7 @@ function(x,FUN, ...) `apply.weekly` <- function(x,FUN, ...) { - if (deparse(substitute(FUN)) == "mean") { + if (deparse(substitute(FUN))[1] == "mean") { .mean_by_column_message("apply.weekly") } ep <- endpoints(x,'weeks') @@ -120,7 +120,7 @@ function(x,FUN, ...) `apply.monthly` <- function(x,FUN, ...) { - if (deparse(substitute(FUN)) == "mean") { + if (deparse(substitute(FUN))[1] == "mean") { .mean_by_column_message("apply.monthly") } ep <- endpoints(x,'months') @@ -130,7 +130,7 @@ function(x,FUN, ...) `apply.quarterly` <- function(x,FUN, ...) { - if (deparse(substitute(FUN)) == "mean") { + if (deparse(substitute(FUN))[1] == "mean") { .mean_by_column_message("apply.quarterly") } ep <- endpoints(x,'quarters') @@ -140,7 +140,7 @@ function(x,FUN, ...) `apply.yearly` <- function(x,FUN, ...) { - if (deparse(substitute(FUN)) == "mean") { + if (deparse(substitute(FUN))[1] == "mean") { .mean_by_column_message("apply.yearly") } ep <- endpoints(x,'years')