Skip to content

Commit 9806e11

Browse files
authored
format with aie (#216)
1 parent e24be81 commit 9806e11

Some content is hidden

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

59 files changed

+2636
-1066
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# tidyhydat 0.7.0.9999
22
- add columns added by a webservice update (#213)
33
- fix some partial matching in `realtime_add_local_datetime` internals
4+
- re-format all code with the lovely air tool
45

56
# tidyhydat 0.7.0
67
- bump minimum R version to 4.2.0

R/cli_style.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and limitations under the License.
1212

13-
1413
## drawing heavily from the tidyverse package
1514

1615
done <- function(msg) {

R/data.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and limitations under the License.
1212

13-
1413
#' All Canadian stations
1514
#'
1615
#' A shorthand to avoid having always call `hy_stations` or `realtime_stations`.
@@ -66,7 +65,7 @@
6665
#' @title Parameter ID
6766
#'
6867
#' @description A tibble of parameter id codes and their corresponding explanation/description specific to the ECCC webservice
69-
#'
68+
#'
7069
#' @format A tibble with 8 rows and 7 variables:
7170
#' \describe{
7271
#' \item{Parameter}{Numeric parameter code}

R/download.R

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) {
3434
if (!dir.exists(dl_hydat_here)) {
3535
dir.create(dl_hydat_here)
3636
message(crayon::blue("You have downloaded hydat to", dl_hydat_here))
37-
message(crayon::blue("See ?hy_set_default_db to change where tidyhydat looks for HYDAT"))
37+
message(crayon::blue(
38+
"See ?hy_set_default_db to change where tidyhydat looks for HYDAT"
39+
))
3840
}
3941
}
4042

4143
if (!is.logical(ask)) stop("Parameter ask must be a logical")
4244

43-
4445
## Create actual hydat_path
4546
hydat_path <- file.path(dl_hydat_here, "Hydat.sqlite3")
4647

@@ -52,7 +53,6 @@ download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) {
5253
existing_hydat <- "HYDAT not present"
5354
}
5455

55-
5656
new_hydat <- hy_remote()
5757
# Make the download URL
5858
url <- paste0(hy_base_url(), "Hydat_sqlite3_", new_hydat, ".zip")
@@ -62,30 +62,40 @@ download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) {
6262
req <- tidyhydat_perform(req)
6363
httr2::resp_check_status(req)
6464

65-
size <- round(as.numeric(
66-
httr2::resp_header(req, "Content-Length")
67-
) / 1000000, 0)
68-
65+
size <- round(
66+
as.numeric(
67+
httr2::resp_header(req, "Content-Length")
68+
) /
69+
1000000,
70+
0
71+
)
6972

7073
## Do we need to download a new version?
71-
if (new_hydat == existing_hydat & ask) { # DB exists and no new version
74+
if (new_hydat == existing_hydat & ask) {
75+
# DB exists and no new version
7276
msg <- paste0(
7377
"The existing local version of HYDAT, published on ",
7478
lubridate::ymd(existing_hydat),
7579
", is the most recent version available. \nDo you wish to overwrite it? \nDownloading HYDAT could take up to 10 minutes (",
76-
size, " MB)."
80+
size,
81+
" MB)."
7782
)
7883
dl_overwrite <- ask(msg)
7984
} else {
8085
dl_overwrite <- TRUE
8186
}
8287

8388
if (!dl_overwrite) {
84-
info("HYDAT is updated on a quarterly basis, check again soon for an updated version.")
89+
info(
90+
"HYDAT is updated on a quarterly basis, check again soon for an updated version."
91+
)
8592
}
86-
if (new_hydat != existing_hydat & ask) { # New DB available or no local DB at all
93+
if (new_hydat != existing_hydat & ask) {
94+
# New DB available or no local DB at all
8795
msg <- paste0(
88-
"This version of HYDAT is ", size, "MB in size and will take some time to download.
96+
"This version of HYDAT is ",
97+
size,
98+
"MB in size and will take some time to download.
8999
\nThis will remove any older versions of HYDAT, if applicable. \nIs that okay?"
90100
)
91101
ans <- ask(msg)
@@ -99,12 +109,18 @@ download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) {
99109
green_message(paste0("Downloading HYDAT to ", dl_hydat_here))
100110
}
101111

102-
103112
if (dl_overwrite) {
104113
if (new_hydat == existing_hydat) {
105-
info(paste0("Your local copy of HYDAT published on ", crayon::blue(lubridate::ymd(new_hydat)), " will be overwritten."))
114+
info(paste0(
115+
"Your local copy of HYDAT published on ",
116+
crayon::blue(lubridate::ymd(new_hydat)),
117+
" will be overwritten."
118+
))
106119
} else {
107-
info(paste0("Downloading new version of HYDAT created on ", crayon::blue(lubridate::ymd(new_hydat))))
120+
info(paste0(
121+
"Downloading new version of HYDAT created on ",
122+
crayon::blue(lubridate::ymd(new_hydat))
123+
))
108124
}
109125

110126
## temporary path to save
@@ -130,7 +146,6 @@ download_hydat <- function(dl_hydat_here = NULL, ask = TRUE) {
130146
overwrite = TRUE
131147
)
132148

133-
134149
if (file.exists(hydat_path)) {
135150
congrats("HYDAT successfully downloaded")
136151
} else {
@@ -160,10 +175,10 @@ hy_remote <- function() {
160175
req <- tidyhydat_perform(req)
161176
resp <- httr2::resp_check_status(req)
162177

163-
164178
raw_date <- substr(
165179
gsub("^.*\\Hydat_sqlite3_", "", httr2::resp_body_string(req)),
166-
1, 8
180+
1,
181+
8
167182
)
168183

169184
raw_date
@@ -182,7 +197,6 @@ hy_check <- function(hydat_path = NULL) {
182197
red_message(paste0(tbl_diff, "\n"))
183198
}
184199

185-
186200
invisible(lapply(have_tbls, function(x) {
187201
tbl_rows <- dplyr::tbl(con, x) |>
188202
utils::head(1) |>

R/hy-classes.R

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ print.hy <- function(x, ...) {
2525
}
2626

2727
summary_msg <- function(x) {
28-
cat(paste0(" Queried from version of HYDAT released on ", as.Date(hy_version()$Date), "\n"))
28+
cat(paste0(
29+
" Queried from version of HYDAT released on ",
30+
as.Date(hy_version()$Date),
31+
"\n"
32+
))
2933

3034
n_records <- format(nrow(x), big.mark = ",")
3135
cat(paste0(" Observations: ", n_records, "\n"))
@@ -36,11 +40,19 @@ summary_msg <- function(x) {
3640
}
3741

3842
if ("PROV_TERR_STATE_LOC" %in% names(x)) {
39-
cat(paste0(" Jurisdictions: ", paste0(unique(x$PROV_TERR_STATE_LOC), collapse = ", "), "\n"))
43+
cat(paste0(
44+
" Jurisdictions: ",
45+
paste0(unique(x$PROV_TERR_STATE_LOC), collapse = ", "),
46+
"\n"
47+
))
4048
}
4149

4250
if ("Parameter" %in% names(x)) {
43-
cat(paste0(" Parameter(s): ", paste0(unique(x$Parameter), collapse = "/"), "\n"))
51+
cat(paste0(
52+
" Parameter(s): ",
53+
paste0(unique(x$Parameter), collapse = "/"),
54+
"\n"
55+
))
4456
}
4557
}
4658

@@ -58,12 +70,17 @@ missed_station_msg <- function(x) {
5870
cat(" Stations requested but not returned: \n")
5971
if (length(differ) != 0) {
6072
if (length(differ) > 50) {
61-
cat(crayon::cyan(" More than 50 stations requested but not returned. \n"))
62-
cat(crayon::cyan(paste0(" See object attributes for complete list of missing stations.\n")))
73+
cat(crayon::cyan(
74+
" More than 50 stations requested but not returned. \n"
75+
))
76+
cat(crayon::cyan(paste0(
77+
" See object attributes for complete list of missing stations.\n"
78+
)))
6379
} else {
6480
cat(
6581
crayon::cyan(
66-
paste0(" ",
82+
paste0(
83+
" ",
6784
strwrap(
6885
paste0(differ, collapse = " "),
6986
width = 40

0 commit comments

Comments
 (0)