Skip to content

Add remove_time_ranges_before function (issue #30) - #32

Merged
jspijker merged 2 commits into
developfrom
issue30
Sep 1, 2026
Merged

jspijker merged 2 commits into
developfrom
issue30

Conversation

@jspijker

@jspijker jspijker commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #30.

What

Adds remove_time_ranges_before(date, conn), which removes measurements from the database based on their download time (the time_dl field in the cache table).

For every cached time range downloaded before the given date, the function:

  • selects the matching cache records;
  • removes that station's measurements between the range start and end, inclusive of the endpoints;
  • if no measurements for the station remain, removes the station from the location table;
  • removes the processed record from the cache table.

It returns a named list keyed by station, each with the start/end of the removed range and a removed boolean indicating whether the station was dropped from the location table.

Changes

  • R/remove_time_ranges_before.R — new function with a roxygen2 header.
  • man/remove_time_ranges_before.Rd, NAMESPACE — generated docs / export.
  • tests/testthat/test-remove_time_ranges_before.R — tests for input validation, inclusive removal, station retention/removal, cutoff handling and return shape.
  • vignettes/ATdatabase.Rmd — new "Remove data" chapter (after "Using the data") explaining the function with an example.

Testing

devtools::test() — all pass (116 assertions, 22 new).

Based on develop.

Add a function to remove measurements based on their download time,
recorded in the cache table's time_dl field. For every cached time
range downloaded before the given date, the measurements of the
station between the range start and end (inclusive) are removed. When
no measurements for a station remain, the station is also removed from
the location table. The processed cache record is removed and a named
list describing the removed ranges is returned.

Includes a roxygen2 header, generated documentation, testthat tests
and a new "Remove data" chapter in the vignette.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@jspijker jspijker left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments in code, please fix the issues

Comment thread R/remove_time_ranges_before.R Outdated
Comment thread vignettes/ATdatabase.Rmd Outdated
Comment thread tests/testthat/test-remove_time_ranges_before.R Outdated
- Make the cutoff inclusive: select cached ranges with time_dl <= date
  and update the roxygen header wording accordingly.
- Update the vignette "Remove data" chapter to say "before or equal to".
- Move the seed_ test helpers into tests/testthat/helper.R and add a
  test for a range downloaded exactly at the cutoff.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jspijker
jspijker merged commit 3777708 into develop Sep 1, 2026
1 check passed
@jspijker
jspijker deleted the issue30 branch September 1, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant