Skip to content

sum() method for Duration class#1177

Open
d-morrison wants to merge 2 commits intotidyverse:mainfrom
d-morrison:sum.Duration
Open

sum() method for Duration class#1177
d-morrison wants to merge 2 commits intotidyverse:mainfrom
d-morrison:sum.Duration

Conversation

@d-morrison
Copy link
Copy Markdown

re: #902

I'm trying to preserve the Duration class through sum(); for example:

Before:

x = lubridate::duration(1:2)
sum(x)
#> [1] 3

After:

x = lubridate::duration(1:2)
sum(x)
#> [1] "3s"
class(x)
#> [1] "Duration"
#> attr(,"package")
#> [1] "lubridate"

Created on 2025-01-15 with reprex v2.1.1

Not sure if this will be helpful, but figured it was worth trying; glad to keep working on a better solution based on your feedback.
I used purrr::reduce(), which I'm guessing introduces an unwanted dependency.
I tried base::Reduce() but it doesn't preserves the Duration class unfortunately.

@vspinu
Copy link
Copy Markdown
Member

vspinu commented Apr 1, 2025

This is really nice addition but I would prefer to avoid adding extra dependency just for this change. It's straightforward to do in plain R.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants