diff --git a/.github/workflows/format-suggest.yaml b/.github/workflows/format-suggest.yaml new file mode 100644 index 0000000..8c4f117 --- /dev/null +++ b/.github/workflows/format-suggest.yaml @@ -0,0 +1,46 @@ +# Workflow derived from https://github.com/posit-dev/setup-air/tree/main/examples + +on: + # Using `pull_request_target` over `pull_request` for elevated `GITHUB_TOKEN` + # privileges, otherwise we can't set `pull-requests: write` when the pull + # request comes from a fork, which is our main use case (external contributors). + # + # `pull_request_target` runs in the context of the target branch (`main`, usually), + # rather than in the context of the pull request like `pull_request` does. Due + # to this, we must explicitly checkout `ref: ${{ github.event.pull_request.head.sha }}`. + # This is typically frowned upon by GitHub, as it exposes you to potentially running + # untrusted code in a context where you have elevated privileges, but they explicitly + # call out the use case of reformatting and committing back / commenting on the PR + # as a situation that should be safe (because we aren't actually running the untrusted + # code, we are just treating it as passive data). + # https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ + pull_request_target: + +name: format-suggest.yaml + +jobs: + format-suggest: + name: format-suggest + runs-on: ubuntu-latest + + permissions: + # Required to push suggestion comments to the PR + pull-requests: write + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Install + uses: posit-dev/setup-air@v1 + + - name: Format + run: air format . + + - name: Suggest + uses: reviewdog/action-suggester@v1 + with: + level: error + fail_level: error + tool_name: air diff --git a/NEWS.md b/NEWS.md index ee26c5d..b6d9086 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # resourcecode (development version) +- `get_parameters` now correctly handles `Date` format as inputs by spanning on the right period; +- Update `rscd_casandra_end_date` with new data availability: 2025-12-31 23:00:00. + # resourcecode 0.5.3 - Custom labels are now handled properly in `cut_seasons()` ; diff --git a/R/download_data.R b/R/download_data.R index 193f134..9fefdf3 100644 --- a/R/download_data.R +++ b/R/download_data.R @@ -186,7 +186,12 @@ get_parameters <- function( origin = as.POSIXct("1970-01-01 00:00:00", tz = "UTC") ) } - + if (lubridate::is.Date(start)) { + start = as.POSIXct(paste(start, "00:00:00"), tz = "UTC") + } + if (lubridate::is.Date(end)) { + end = as.POSIXct(paste(end, "23:00:00"), tz = "UTC") + } if (start < rscd_casandra_start_date) { stop( "'start' is outside the covered period: ", diff --git a/R/sysdata.rda b/R/sysdata.rda index 22e09e0..2eef2b7 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/data/rscd_data_example.rda b/data/rscd_data_example.rda index 280e138..9067d20 100644 Binary files a/data/rscd_data_example.rda and b/data/rscd_data_example.rda differ diff --git a/data/rscd_dir.rda b/data/rscd_dir.rda index 7734315..e90532e 100644 Binary files a/data/rscd_dir.rda and b/data/rscd_dir.rda differ diff --git a/data/rscd_freq.rda b/data/rscd_freq.rda index 314ab6f..7a1f154 100644 Binary files a/data/rscd_freq.rda and b/data/rscd_freq.rda differ diff --git a/devtools_history.R b/devtools_history.R index ce40bcc..75d67aa 100644 --- a/devtools_history.R +++ b/devtools_history.R @@ -35,7 +35,7 @@ rscd_hindcast_start_date = as.POSIXct("1994-01-01 00:00:00", tz = 'UTC') rscd_hindcast_end_date = as.POSIXct("2024-12-31 23:00:00", tz = 'UTC') rscd_casandra_start_date = as.POSIXct("1994-01-01 00:00:00", tz = 'UTC') -rscd_casandra_end_date = as.POSIXct("2020-12-31 23:00:00", tz = 'UTC') +rscd_casandra_end_date = as.POSIXct("2025-12-31 23:00:00", tz = 'UTC') usethis::use_data( rcd_cassandra_url, @@ -43,8 +43,8 @@ usethis::use_data( rscd_hindcast_end_date, rscd_casandra_start_date, rscd_casandra_end_date, - rscd_freq, - rscd_dir, + #rscd_freq, + #rscd_dir, internal = TRUE, version = 3, overwrite = TRUE @@ -92,17 +92,10 @@ usethis::use_coverage(type = "codecov") devtools::build_readme() usethis::use_github_action("test-coverage") -#Rcpp Armadillo for fast multivariate trapz -usethis::use_rcpp_armadillo("fast_trapz.cpp") -usethis::use_rcpp("ww_calc_cpp.cpp") - -# Lintr checks and GHA -install.packages("lintr") -install.packages("styler") -lintr::use_lintr() - -lintr::lint_package() -usethis::use_github_action("lint") +#Air formating and GHA +usethis::use_github_action( + url = "https://github.com/posit-dev/setup-air/blob/main/examples/format-suggest.yaml" +) devtools::load_all() devtools::spell_check() diff --git a/tests/testthat/tests_download_parameters.R b/tests/testthat/tests_download_parameters.R index 664e08d..6c63ebb 100644 --- a/tests/testthat/tests_download_parameters.R +++ b/tests/testthat/tests_download_parameters.R @@ -53,6 +53,19 @@ test_that("get_parameters handles character date inputs", { expect_true(nrow(result) > 0) }) +test_that("get_parameters handles Date format as input", { + vcr::local_cassette("Date_dates") + result <- get_parameters( + parameters = "hs", + node = 42, + start = as.Date("1994-01-01"), + end = as.Date("1994-01-01") + ) + + expect_s3_class(result, "data.frame") + expect_true(nrow(result) > 1) +}) + test_that("get_parameters handles numeric date inputs", { vcr::local_cassette("numeric_dates") start_num <- as.numeric(as.POSIXct("1994-01-01 00:00:00", tz = "UTC"))