Skip to content

Commit

Permalink
Switch from timetk to slider for sliding window
Browse files Browse the repository at this point in the history
`timetk` got archived from CRAN at one point, causing this package to get archived as well.

While `timetk` is back up, we only use it for a single function, and that function is basically a re-export from the lower-level `slider` package.

So this removes our dependency on `timetk` and replaces it with a dependency on `slider` instead.

As it turns out, this also gives us better results, since we're able to more clearly note that we're looking for a sliding window on the "time" column of 30 seconds. So the test is updated, and the results look more correct.

Resolves #2
  • Loading branch information
dschafer committed May 1, 2023
1 parent 775c49b commit d81bcbd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Imports:
magrittr (>= 2.0.0),
rlang (>= 0.4.0),
tibble (>= 3.0.0),
timetk (>= 2.6.0),
slider (>= 0.3.0),
xml2 (>= 1.3.2)
RoxygenNote: 7.1.1
RoxygenNote: 7.2.3
Suggests:
covr (>= 3.5.0),
lintr (>= 3.0.0),
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ importFrom(lubridate,ymd_hms)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
importFrom(rlang,abort)
importFrom(slider,slide_index_dbl)
importFrom(tibble,add_column)
importFrom(tibble,is_tibble)
importFrom(tibble,tibble)
importFrom(tibble,tribble)
importFrom(timetk,slidify)
importFrom(utils,head)
importFrom(xml2,read_xml)
importFrom(xml2,xml_add_child)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# activatr (development version)

* Switch dependency from `timetk` to `slider` to avoid unnecessary indirection (#3).

# activatr 0.1.0

* Initial release.
17 changes: 9 additions & 8 deletions R/act_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ is_act_tbl <- function(act_tbl) {
#' @return \code{summary.act_tbl} returns a tibble with a single row,
#' containing a summary of the given \code{act_tbl}.
#' @importFrom dplyr lag mutate pull slice
#' @importFrom lubridate as.duration
#' @importFrom timetk slidify
#' @importFrom lubridate as.duration dseconds
#' @importFrom slider slide_index_dbl
#' @importFrom tibble tribble
#' @rdname act_tbl
summary.act_tbl <- function(object,
Expand Down Expand Up @@ -158,15 +158,16 @@ summary.act_tbl <- function(object,
# If we have elevation, add AvgElev, ElevGain and ElevLoss
if ("ele" %in% colnames(object)) {
# We use a rolling 30 second average of elevation to smooth out jitter.
period <- min(30, nrow(object))
period <- dseconds(min(15, nrow(object)))
elev_df <- object %>%
mutate(
ele = slidify(
ele = slide_index_dbl(
.data$ele,
.data$time,
mean,
.period = period,
.align = "center",
.partial = TRUE
)(.data$ele)
.before = period,
.after = period
)
) %>%
mutate(
elevdelta = .data$ele - lag(.data$ele),
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test_act_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ test_that("summary works", {
expect_equal(as.integer(s$MaxPace), 356)

expect_equal(as.integer(s$AvgElev), 765)
expect_equal(as.integer(s$ElevGain), 382)
expect_equal(as.integer(s$ElevLoss), 54)
expect_equal(as.integer(s$ElevGain), 1640)
expect_equal(as.integer(s$ElevLoss), 984)
})

test_that("summary allows use of full to fill in missing columns", {
Expand Down Expand Up @@ -76,8 +76,8 @@ test_that("summary allows for metric system", {
expect_equal(as.integer(s$MaxPace), 221)

expect_equal(as.integer(s$AvgElev), 233)
expect_equal(as.integer(s$ElevGain), 116)
expect_equal(as.integer(s$ElevLoss), 16)
expect_equal(as.integer(s$ElevGain), 500)
expect_equal(as.integer(s$ElevLoss), 300)
})

test_that("summary includes hr when provided", {
Expand Down

0 comments on commit d81bcbd

Please sign in to comment.