Skip to content

Commit

Permalink
Fixes tests and passes checks now
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhsparks committed May 16, 2024
1 parent 7e7d5a5 commit fe5e958
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 115 deletions.
5 changes: 4 additions & 1 deletion R/get_data_drill_apsim.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#' @param api_key A `character `string specifying a valid email address to use
#' for the request. The query will return an error if a valid email address
#' is not provided.
#' @param filename A `character` string providing an optional value for the
#' \dQuote{filename} field in the .met file.
#'
#' @section Included Values:
#'
Expand Down Expand Up @@ -103,7 +105,8 @@ get_data_drill_apsim <- function(longitude,
latitude,
start_date,
end_date = Sys.Date(),
api_key) {
api_key,
filename) {
if (missing(longitude) || missing(latitude)) {
stop(call. = FALSE,
"Please supply a valid values for `longitude` and `latitude`.")
Expand Down
9 changes: 6 additions & 3 deletions R/get_patched_point_apsim.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
#' @param end_date A `character` string or `Date` object representing the end of
#' the range query in the format \dQuote{yyyy-mm-dd} (ISO8601). Data
#' returned is inclusive of this date. Defaults to the current system date.
#' @param api_key A `character` string specifying a valid email address to use
#' @param api_key A `character` string providing a valid email address to use
#' for the request. The query will return an error if a valid email address
#' is not provided.
#' @param filename A `character` string providing an optional value for the
#' \dQuote{filename} field in the .met file.
#'
#' @section Included Values:
#'
Expand Down Expand Up @@ -92,7 +94,7 @@
#' @examples
#' \dontrun{
#' # requires an API key as your email address
#' # Source observation data for station Wongan Hills station, WA (008137)
#' # Source observation data for Wongan Hills station, WA (008137)
#' wd <- get_patched_point_apsim(
#' station_code = "008137",
#' start_date = "20220101",
Expand All @@ -112,7 +114,8 @@
get_patched_point_apsim <- function(station_code,
start_date,
end_date = Sys.Date(),
api_key) {
api_key,
filename) {
if (missing(station_code) | !is.character(station_code)) {
stop(call. = FALSE,
"Please supply a valid `station_code`.")
Expand Down
6 changes: 3 additions & 3 deletions R/query_silo_api.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#' Query the SILO API
#'
#' Use {crul} to query the SILO API.
#' Use \CRANpkg{crul} to query the SILO API.
#'
#' @param .station_code A `character` string of the \acronym{BOM} station code
#' for the station of interest.
Expand Down Expand Up @@ -120,8 +120,8 @@
}

if (.format == "apsim") {
met_file_path <- file.path(tempdir(), "apsim.met")
on.exit(unlink(met_file_path))
met_file_path <- tempfile()
on.exit(unlink(tempfile()))
writeLines(text = response$parse("UTF8"), con = met_file_path)
apsim <- readLines(met_file_path)
data <- data.table::fread(file = met_file_path,
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ minimise
modelling
mungbean
mungbeans
noname
observationsCount
observationsPercentage
oktas
Expand Down
6 changes: 5 additions & 1 deletion man/get_data_drill_apsim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions man/get_patched_point_apsim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/fixtures/dpird_apsim.json

This file was deleted.

2 changes: 1 addition & 1 deletion tests/fixtures/silo_get_data_drill_apsim.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/fixtures/silo_get_patched_point_apsim.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions tests/testthat/test-get_data_drill_apsim.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ test_that("get_data_drill_apsim() user-input checks stop on invalid values",
expect_error(
get_data_drill_apsim(
latitude = -27.85,
start_date = "20220501",
end_date = "20220501",
start_date = "20220101",
end_date = "20221231",
api_key = Sys.getenv("SILO_API_KEY")
)
)
Expand Down Expand Up @@ -46,13 +46,13 @@ test_that("get_data_drill_apsim() returns all daily values", {
wd <- get_data_drill_apsim(
latitude = -27.85,
longitude = 150.05,
start_date = "2021-06-01",
end_date = "2021-07-01",
start_date = "2021-01-01",
end_date = "2021-12-31",
api_key = "slavish_moo_0k@icloud.com"
)
})
expect_s3_class(wd, class = "met")
expect_equal(nrow(wd), 31)
expect_equal(nrow(wd), 364)
expect_length(wd, 9)
expect_named(wd,
c(
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-get_dpird_apsim.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

test_that("get_dpird_apsim() returns a 'met' object",
{
vcr::use_cassette("dpird_apsim", {
vcr::use_cassette("dpird_get_apsim", {
skip_if_offline()
x <- get_dpird_apsim(
expect_warning(x <- get_dpird_apsim(
station_code = "BI",
start_date = "20170228",
end_date = "20170228",
start_date = "20170101",
end_date = "20171231",
api_key = Sys.getenv("DPIRD_API_KEY")
)
))
})
expect_s3_class(x, "met")
expect_length(x, 9)
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-get_patched_point_apsim.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ test_that("get_patched_point_apsim() input checks stop on invalid values", {
# missing station_code
expect_error(
get_patched_point_apsim(
start_date = "20220501",
end_date = "20220501",
start_date = "20220101",
end_date = "20221231",
api_key = Sys.getenv("SILO_API_KEY")
)
)
Expand Down Expand Up @@ -35,12 +35,12 @@ test_that("get_patched_point_apsim() returns daily values", {
withr::local_timezone(tz = "Australia/Perth")
wd <- get_patched_point_apsim(
station_code = "008137",
start_date = "2021-06-01",
end_date = "2021-07-01",
start_date = "2021-01-01",
end_date = "2021-12-31",
api_key = "slavish_moo_0k@icloud.com"
)
})
expect_equal(nrow(wd), 31)
expect_equal(nrow(wd), 364)
expect_length(wd, 9)
expect_named(wd,
c(
Expand Down

0 comments on commit fe5e958

Please sign in to comment.