Skip to content

Commit 11947f0

Browse files
authored
fix spelling error and a few other bugs, updates tests (#99)
* fix spelling error * allow users to provide a service in case other than just uppper * update documentation * update vcr fixtures for tests * update roxygen note * update codemeta.json * make get_key() more reable for programmers and error messages for end users * update codemeta.json * fix documentation patched point item for rain description was incorrect line breaks in find_forecast_towns * update documentation with corrections and line breaks
1 parent 3c6f76e commit 11947f0

File tree

50 files changed

+481
-492
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+481
-492
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Language: en-US
114114
LazyData: true
115115
Roxygen: list(markdown = TRUE, roclets = c("collate", "namespace", "rd",
116116
"roxyglobals::global_roclet"))
117-
RoxygenNote: 7.3.2
117+
RoxygenNote: 7.3.3
118118
X-schema.org-applicationCategory: Tools
119119
X-schema.org-isPartOf: https://ropensci.org
120120
X-schema.org-keywords: dpird, bom, meteorological-data, weather-forecast,

R/find_forecast_towns.R

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#' Find the Nearest Town With a BOM Forecast
32
#'
43
#' For a given `latitude` and `longitude`, find the nearest town that the
@@ -16,8 +15,8 @@
1615
#' # find forecast towns near Esperance, WA
1716
#' find_forecast_towns(longitude = 121.8913, latitude = -33.8614)
1817
#'
19-
#' @return A [data.table::data.table()] of all forecast towns (in this package) sorted by
20-
#' distance from \var{latitude} and \var{longitude}, ascending.
18+
#' @return A [data.table::data.table()] of all forecast towns (in this package)
19+
#' sorted by distance from \var{latitude} and \var{longitude}, ascending.
2120
#' @author Hugh Parsonage, \email{hugh.parsonage@@gmail.com}, and James Goldie,
2221
#' \email{me@@jamesgoldie.dev}, and Adam H. Sparks,
2322
#' \email{adamhsparks@@gmail.com}
@@ -28,9 +27,7 @@
2827
#' @export
2928

3029
find_forecast_towns <-
31-
function(longitude = 149.2,
32-
latitude = -35.3,
33-
distance_km = 100) {
30+
function(longitude = 149.2, latitude = -35.3, distance_km = 100) {
3431
lonlat <- .check_lonlat(longitude = longitude, latitude = latitude)
3532

3633
user_longitude <- lonlat["longitude"]
@@ -51,30 +48,41 @@ find_forecast_towns <-
5148

5249
forecast_towns <-
5350
data.table::data.table(foreign::read.dbf(file_dbf, as.is = TRUE))
54-
data.table::setnames(forecast_towns, names(forecast_towns),
55-
tolower(names(forecast_towns)))
51+
data.table::setnames(
52+
forecast_towns,
53+
names(forecast_towns),
54+
tolower(names(forecast_towns))
55+
)
5656
data.table::setcolorder(forecast_towns, c(2:3, 7:9))
57-
data.table::setnames(forecast_towns,
58-
old = c("pt_name", "lat", "lon", "elevation"),
59-
new = c("town", "latitude", "longitude", "elev_m"))
60-
forecast_towns <- forecast_towns[, c("aac",
61-
"town",
62-
"longitude",
63-
"latitude",
64-
"elev_m")]
57+
data.table::setnames(
58+
forecast_towns,
59+
old = c("pt_name", "lat", "lon", "elevation"),
60+
new = c("town", "latitude", "longitude", "elev_m")
61+
)
62+
forecast_towns <- forecast_towns[, c(
63+
"aac",
64+
"town",
65+
"longitude",
66+
"latitude",
67+
"elev_m"
68+
)]
6569
data.table::setkey(forecast_towns, "aac")
6670

67-
forecast_towns[, "distance" := .haversine_distance(
68-
lat1 = latitude,
69-
lon1 = longitude,
70-
lat2 = user_latitude,
71-
lon2 = user_longitude
72-
)] |>
71+
forecast_towns[,
72+
"distance" := .haversine_distance(
73+
lat1 = latitude,
74+
lon1 = longitude,
75+
lat2 = user_latitude,
76+
lon2 = user_longitude
77+
)
78+
] |>
7379
data.table::setorderv("distance")
7480

7581
forecast_towns[, distance := round(distance, 1)]
76-
out <- forecast_towns[distance %in%
77-
forecast_towns[(distance <= distance_km)]$distance]
82+
out <- forecast_towns[
83+
distance %in%
84+
forecast_towns[(distance <= distance_km)]$distance
85+
]
7886
data.table::setkey(out, "aac")
7987
return(out[])
8088
}

R/get_key.R

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,64 +26,66 @@
2626
#'
2727
#' @export
2828
get_key <- function(service = c("DPIRD", "SILO")) {
29+
service <- toupper(service)
2930

3031
service <- match.arg(service)
3132

3233
if (service == "DPIRD") {
3334
DPIRD_API_KEY <- Sys.getenv("DPIRD_API_KEY")
34-
35-
if (!nzchar(DPIRD_API_KEY)) {
36-
.set_dpird_key()
37-
} else {
35+
if (nzchar(DPIRD_API_KEY)) {
3836
return(DPIRD_API_KEY)
3937
}
38+
return(.set_dpird_key())
4039
} else {
4140
SILO_API_KEY <- Sys.getenv("SILO_API_KEY")
42-
if (!nzchar(SILO_API_KEY)) {
43-
.set_silo_key()
44-
} else {
41+
if (nzchar(SILO_API_KEY)) {
4542
return(SILO_API_KEY)
4643
}
44+
return(.set_silo_key())
4745
}
4846
}
4947

50-
#' Help the User Request an API Key for the DPIRD API
51-
#'
52-
#' Opens a browser window at the DPIRD API key request URL and provides
53-
#' instruction on how to store the key. After filling the form you will get
54-
#' the key soon, but not immediately.
55-
#'
56-
#' @keywords internal
57-
#' @noRd
58-
#' @return Called for its side-effects, opens a browser window at the DPIRD
59-
#' weather data API key request form.
60-
.set_dpird_key <- function() {
61-
if (interactive()) {
62-
utils::browseURL("https://www.dpird.wa.gov.au/forms/dpird-api-registration/")
63-
}
64-
65-
stop(
66-
"You need to set your DPIRD API key.\n",
67-
"After getting your key set it as 'DPIRD_API_KEY' in .Renviron.\n",
68-
"DPIRD_API_KEY='youractualkeynotthisstring'\n",
69-
"For that, use `usethis::edit_r_environ()`"
48+
#' Help the User Request an API Key for the DPIRD API
49+
#'
50+
#' Opens a browser window at the DPIRD API key request URL and provides
51+
#' instruction on how to store the key. After filling the form you will get
52+
#' the key soon, but not immediately.
53+
#'
54+
#' @keywords internal
55+
#' @noRd
56+
#' @return Called for its side-effects, opens a browser window at the DPIRD
57+
#' weather data API key request form.
58+
.set_dpird_key <- function() {
59+
if (interactive()) {
60+
utils::browseURL(
61+
"https://www.dpird.wa.gov.au/forms/dpird-api-registration/"
7062
)
7163
}
7264

73-
#' Help the User Set Up Their SILO API Key
74-
#'
75-
#' Instructs the user on how to set up the SILO API key to automatically find
76-
#' it.
77-
#'
78-
#' @return Invisible `NULL`, called for its side-effects, returns a message
79-
#' with instructions.
80-
#' @keywords internal
81-
#' @noRd
65+
stop(
66+
"You need to set your DPIRD API key.\n",
67+
"After getting your key set it as 'DPIRD_API_KEY' in .Renviron.\n",
68+
"DPIRD_API_KEY='youractualkeynotthisstring'\n",
69+
"For that, use `usethis::edit_r_environ()`",
70+
call. = FALSE
71+
)
72+
}
73+
74+
#' Help the User Set Up Their SILO API Key
75+
#'
76+
#' Instructs the user on how to set up the SILO API key to automatically find
77+
#' it.
78+
#'
79+
#' @return Invisible `NULL`, called for its side-effects, returns a message
80+
#' with instructions.
81+
#' @keywords internal
82+
#' @noRd
8283

83-
.set_silo_key <- function() {
84-
stop(
85-
"Set your SILO API key (email address) as 'SILO_API_KEY' in .Renviron.\n",
86-
"SILO_API_KEY='youractualemailnotthisstring'\n",
87-
"For that, use `usethis::edit_r_environ()`"
88-
)
89-
}
84+
.set_silo_key <- function() {
85+
stop(
86+
"Set your SILO API key (email address) as 'SILO_API_KEY' in .Renviron.\n",
87+
"SILO_API_KEY='youractualemailnotthisstring'\n",
88+
"For that, use `usethis::edit_r_environ()`",
89+
call. = FALSE
90+
)
91+
}

R/get_patched_point.R

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#' Get PatchedPoint Weather Data From SILO
32
#'
43
#' Fetch nicely formatted weather data from the \acronym{SILO} \acronym{API}
@@ -50,7 +49,7 @@
5049
#'
5150
#' \describe{
5251
#' \item{all}{Which will return all of the following values}
53-
#' \item{rain (mm)}{Rainfall}
52+
#' \item{rain}{Rainfall}
5453
#' \item{max_temp (degrees C)}{Maximum temperature}
5554
#' \item{min_temp (degrees C)}{Minimum temperature}
5655
#' \item{vp (hPa)}{Vapour pressure}
@@ -169,26 +168,26 @@
169168
#' @autoglobal
170169
#' @export
171170

172-
get_patched_point <- function(station_code,
173-
start_date,
174-
end_date = Sys.Date(),
175-
values = "all",
176-
api_key = get_key(service = "SILO")) {
177-
171+
get_patched_point <- function(
172+
station_code,
173+
start_date,
174+
end_date = Sys.Date(),
175+
values = "all",
176+
api_key = get_key(service = "SILO")
177+
) {
178178
# simplify using the metadata to fetch weather data by converting factors to
179179
# numeric values
180180
if (inherits(x = station_code, what = "factor")) {
181181
station_code <- as.character(station_code)
182182
}
183183

184184
if (missing(station_code) | !is.character(station_code)) {
185-
stop(call. = FALSE,
186-
"Please supply a valid `station_code`.")
185+
stop(call. = FALSE, "Please supply a valid `station_code`.")
187186
}
188187

189-
if (missing(start_date))
190-
stop(call. = FALSE,
191-
"Please supply a valid start date as `start_date`.")
188+
if (missing(start_date)) {
189+
stop(call. = FALSE, "Please supply a valid start date as `start_date`.")
190+
}
192191

193192
.check_not_example_api_key(api_key)
194193
.is_valid_email_silo_api_key(api_key)
@@ -217,13 +216,10 @@ get_patched_point <- function(station_code,
217216
)
218217

219218
data.table::setcolorder(out, order(names(out)))
220-
data.table::setcolorder(out,
221-
c("station_code",
222-
"station_name",
223-
"year",
224-
"month",
225-
"day",
226-
"date"))
219+
data.table::setcolorder(
220+
out,
221+
c("station_code", "station_name", "year", "month", "day", "date")
222+
)
227223

228224
out[]
229225
}

codemeta.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
33
"@type": "SoftwareSourceCode",
44
"identifier": "weatherOz",
5-
"description": "Provides automated downloading, parsing and formatting of weather data for Australia through API endpoints provided by the Department of Primary Industries and Regional Development ('DPIRD') of Western Australia and by the Science and Technology Division of the Queensland Government's Department of Environment and Science ('DES'). As well as the Bureau of Meteorology ('BOM') of the Australian government precis and coastal forecasts, and downloading and importing radar and satellite imagery files. 'DPIRD' weather data are accessed through public 'APIs' provided by 'DPIRD', <https://www.dpird.wa.gov.au/online-tools/apis/>, providing access to weather station data from the 'DPIRD' weather station network. Australia-wide weather data are based on data from the Australian Bureau of Meteorology ('BOM') data and accessed through 'SILO' (Scientific Information for Land Owners) Jeffrey et al. (2001) <doi:10.1016/S1364-8152(01)00008-1>. 'DPIRD' data are made available under a Creative Commons Attribution 3.0 Licence (CC BY 3.0 AU) license <https://creativecommons.org/licenses/by/3.0/au/deed.en>. SILO data are released under a Creative Commons Attribution 4.0 International licence (CC BY 4.0) <https://creativecommons.org/licenses/by/4.0/>. 'BOM' data are (c) Australian Government Bureau of Meteorology and released under a Creative Commons (CC) Attribution 3.0 licence or Public Access Licence ('PAL') as appropriate, see <http://www.bom.gov.au/other/copyright.shtml> for further details.",
5+
"description": "Provides automated downloading, parsing and formatting of weather data for Australia through API endpoints provided by the Department of Primary Industries and Regional Development (DPIRD) of Western Australia and by the Science and Technology Division of the Queensland Government's Department of Environment and Science (DES). As well as the Bureau of Meteorology (BOM) of the Australian government precis and coastal forecasts, and downloading and importing radar and satellite imagery files. DPIRD weather data are accessed through public APIs provided by DPIRD, <https://www.dpird.wa.gov.au/online-tools/apis/>, providing access to weather station data from the DPIRD weather station network. Australia-wide weather data are based on data from the Australian Bureau of Meteorology (BOM) data and accessed through SILO (Scientific Information for Land Owners) Jeffrey et al. (2001) <doi:10.1016/S1364-8152(01)00008-1>. DPIRD data are made available under a Creative Commons Attribution 3.0 Licence (CC BY 3.0 AU) license <https://creativecommons.org/licenses/by/3.0/au/deed.en>. SILO data are released under a Creative Commons Attribution 4.0 International licence (CC BY 4.0) <https://creativecommons.org/licenses/by/4.0/>. BOM data are (c) Australian Government Bureau of Meteorology and released under a Creative Commons (CC) Attribution 3.0 licence or Public Access Licence (PAL) as appropriate, see <http://www.bom.gov.au/other/copyright.shtml> for further details.",
66
"name": "weatherOz: An API Client for Australian Weather and Climate Data Resources",
77
"relatedLink": ["https://docs.ropensci.org/weatherOz/", "https://CRAN.R-project.org/package=weatherOz"],
88
"codeRepository": "https://github.com/ropensci/weatherOz/",
@@ -14,7 +14,7 @@
1414
"name": "R",
1515
"url": "https://r-project.org"
1616
},
17-
"runtimePlatform": "R version 4.4.3 (2025-02-28)",
17+
"runtimePlatform": "R version 4.5.2 (2025-10-31)",
1818
"provider": {
1919
"@id": "https://cran.r-project.org",
2020
"@type": "Organization",
@@ -313,7 +313,7 @@
313313
"@type": "SoftwareApplication",
314314
"identifier": "vcr",
315315
"name": "vcr",
316-
"version": ">= 0.6.0",
316+
"version": ">= 2.0.0",
317317
"provider": {
318318
"@id": "https://cran.r-project.org",
319319
"@type": "Organization",
@@ -392,27 +392,28 @@
392392
},
393393
"5": {
394394
"@type": "SoftwareApplication",
395-
"identifier": "crul",
396-
"name": "crul",
395+
"identifier": "curl",
396+
"name": "curl",
397397
"provider": {
398398
"@id": "https://cran.r-project.org",
399399
"@type": "Organization",
400400
"name": "Comprehensive R Archive Network (CRAN)",
401401
"url": "https://cran.r-project.org"
402402
},
403-
"sameAs": "https://CRAN.R-project.org/package=crul"
403+
"sameAs": "https://CRAN.R-project.org/package=curl"
404404
},
405405
"6": {
406406
"@type": "SoftwareApplication",
407-
"identifier": "curl",
408-
"name": "curl",
407+
"identifier": "crul",
408+
"name": "crul",
409+
"version": ">= 1.6.0",
409410
"provider": {
410411
"@id": "https://cran.r-project.org",
411412
"@type": "Organization",
412413
"name": "Comprehensive R Archive Network (CRAN)",
413414
"url": "https://cran.r-project.org"
414415
},
415-
"sameAs": "https://CRAN.R-project.org/package=curl"
416+
"sameAs": "https://CRAN.R-project.org/package=crul"
416417
},
417418
"7": {
418419
"@type": "SoftwareApplication",
@@ -560,7 +561,7 @@
560561
"applicationCategory": "Tools",
561562
"isPartOf": "https://ropensci.org",
562563
"keywords": ["dpird", "bom", "meteorological-data", "weather-forecast", "australia", "weather", "weather-data", "meteorology", "western-australia", "australia-bureau-of-meteorology", "western-australia-agriculture", "australia-agriculture", "australia-climate", "australia-weather", "rstats", "climate", "api-client", "data", "weather-api", "rainfall", "r"],
563-
"fileSize": "5505.495KB",
564+
"fileSize": "5520.013KB",
564565
"citation": [
565566
{
566567
"@type": "ScholarlyArticle",
@@ -691,12 +692,12 @@
691692
"name": "{weatherOz}: An API Client for Australian Weather and Climate Data Resources in R",
692693
"identifier": "10.5281/zenodo.8191283",
693694
"url": "https://docs.ropensci.org/weatherOz/",
694-
"description": "R package version 2.0.0",
695+
"description": "R package version 2.0.2",
695696
"@id": "https://doi.org/10.5281/zenodo.8191283",
696697
"sameAs": "https://doi.org/10.5281/zenodo.8191283"
697698
}
698699
],
699-
"releaseNotes": "https://github.com/ropensci/weatherOz/blob/master/NEWS.md",
700+
"releaseNotes": "https://github.com/ropensci/weatherOz/blob/main/NEWS.md",
700701
"readme": "https://github.com/ropensci/weatherOz/blob/main/README.md",
701702
"contIntegration": ["https://github.com/ropensci/weatherOz/actions/workflows/R-CMD-check.yaml", "https://app.codecov.io/gh/ropensci/weatherOz"],
702703
"developmentStatus": "https://lifecycle.r-lib.org/articles/stages.html#stable",

man/find_forecast_towns.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/find_stations_in.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_available_imagery.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)