Skip to content

Commit

Permalink
Fix if-statement when deparsed FUN length is > 1
Browse files Browse the repository at this point in the history
The if-statement would error if `FUN = function(x) mean(x)` because
deparse(substitute(FUN)) has more than one element.
  • Loading branch information
joshuaulrich committed Sep 25, 2023
1 parent d9ff328 commit 17151a5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/period.apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit 17151a5

Please sign in to comment.