Skip to content

Commit 964b5fc

Browse files
committed
Avoid printing internet connection messages twice
1 parent 7c92ca9 commit 964b5fc

7 files changed

Lines changed: 57 additions & 51 deletions

File tree

‎r-package/NEWS.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
**Minor changes**
44

5-
- Error messages now use {cli}
5+
- Messages and errors now use {cli}
6+
- Avoid printing internet connection messages twice
67

78
**Bug fixes**
89

‎r-package/R/download_metadata.R‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ download_metadata <- function(){ # nocov start
5555

5656
# check if data was read Ok
5757
if (nrow(metadata)==0) {
58-
message("A file must have been corrupted during download. Please restart your R session and download the data again.")
58+
msg <- "A file must have been corrupted during download. Please restart your R session and download the data again."
59+
cli::cli_alert_danger(msg)
5960
return(invisible(NULL))
6061
}
6162

‎r-package/R/read_access.R‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,21 @@ read_access <- function(city = NULL,
225225
aop <- aop_merge(aop_landuse, aop_access)
226226

227227
# with Vs without spatial data
228-
if(geometry == FALSE){
229-
# return df
230-
return(aop)
231-
232-
} else {
233-
234-
# return sf
235-
aop_grid <- read_grid(city=city, showProgress=showProgress)
236-
237-
# check if download failed
238-
check_downloaded_obj(aop_grid) # nocov
239-
if (is.null(aop_grid)) { return(invisible(NULL)) }
240-
241-
aop_sf <- aop_spatial_join(aop, aop_grid)
242-
return(aop_sf)
243-
}
228+
if (geometry == FALSE) {
229+
# return df
230+
return(aop)
231+
232+
} else {
233+
# return sf
234+
aop_grid <- suppressMessages(
235+
read_grid(city = city, showProgress = showProgress)
236+
)
237+
238+
# check if download failed
239+
check_downloaded_obj(aop_grid) # nocov
240+
if (is.null(aop_grid)) { return(invisible(NULL)) }
241+
242+
aop_sf <- aop_spatial_join(aop, aop_grid)
243+
return(aop_sf)
244+
}
244245
}

‎r-package/R/read_landuse.R‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,22 @@ read_landuse <- function(city = NULL,
134134
aop <- data.table::merge.data.table(aop_population, aop_landuse, by = c('id_hex', 'abbrev_muni', 'name_muni', 'code_muni'), all = TRUE)
135135

136136
# with Vs without spatial data
137-
if(geometry == FALSE){
138-
# return df
139-
return(aop)
137+
if (geometry == FALSE) {
138+
# return df
139+
return(aop)
140140

141-
} else {
142-
143-
# return sf
144-
aop_grid <- read_grid(city=city, showProgress=showProgress)
145-
146-
# check if download failed
147-
check_downloaded_obj(aop_grid) # nocov
148-
if (is.null(aop_grid)) { return(invisible(NULL)) }
141+
} else {
142+
# return sf
143+
aop_grid <- suppressMessages(
144+
read_grid(city = city, showProgress = showProgress)
145+
)
149146

147+
# check if download failed
148+
check_downloaded_obj(aop_grid) # nocov
149+
if (is.null(aop_grid)) { return(invisible(NULL)) }
150150

151-
# create function aop_join to bring in land use info
152-
aop_sf <- aop_spatial_join(aop, aop_grid)
153-
return(aop_sf)
154-
}
151+
# create function aop_join to bring in land use info
152+
aop_sf <- aop_spatial_join(aop, aop_grid)
153+
return(aop_sf)
154+
}
155155
}

‎r-package/R/read_population.R‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,22 @@ read_population <- function(city = NULL,
105105
if (is.null(aop_population)) { return(invisible(NULL)) }
106106

107107
# with Vs without spatial data
108-
if(geometry == FALSE){
109-
# return df
110-
return(aop_population)
108+
if (geometry == FALSE) {
109+
# return df
110+
return(aop_population)
111111

112-
} else {
112+
} else {
113+
# return sf
114+
aop_grid <- suppressMessages(
115+
read_grid(city = city, showProgress = showProgress)
116+
)
113117

114-
# return sf
115-
aop_grid <- read_grid(city=city, showProgress=showProgress)
118+
# check if download failed
119+
check_downloaded_obj(aop_grid) # nocov
120+
if (is.null(aop_grid)) { return(invisible(NULL)) }
116121

117-
# check if download failed
118-
check_downloaded_obj(aop_grid) # nocov
119-
if (is.null(aop_grid)) { return(invisible(NULL)) }
120-
121-
# create function aop_join to bring in land use info
122-
aop_sf <- aop_spatial_join(aop_population, aop_grid)
123-
return(aop_sf)
124-
}
122+
# create function aop_join to bring in land use info
123+
aop_sf <- aop_spatial_join(aop_population, aop_grid)
124+
return(aop_sf)
125+
}
125126
}

‎r-package/R/utils.R‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ download_data <- function(url, progress_bar = showProgress){
209209
# if server1 fails, replace url and test connection with server2
210210
if (is.null(check_con) | isFALSE(check_con)) {
211211
url <- url2
212-
try( silent = TRUE, check_con <- check_connection(url[1], silent = FALSE))
212+
try( silent = TRUE, check_con <- check_connection(url[1], silent = TRUE))
213213
if (is.null(check_con) | isFALSE(check_con)) { return(invisible(NULL)) }
214214
}
215215

@@ -228,8 +228,8 @@ download_data <- function(url, progress_bar = showProgress){
228228

229229
# if anything fails, return NULL
230230
if (any(!downloaded_files$success | is.na(downloaded_files$success))) {
231-
msg <- paste("File cached locally seems to be corrupted. Please download it again.")
232-
message(msg)
231+
msg <- "File cached locally seems to be corrupted. Please download it again."
232+
cli::cli_alert_danger(msg)
233233
return(invisible(NULL))
234234
}
235235

@@ -282,7 +282,8 @@ load_data <- function(temps=NULL){
282282

283283
# check if data was read Ok
284284
if (nrow(temp)==0) {
285-
message("A file must have been corrupted during download. Please restart your R session and download the data again.")
285+
msg <- "A file must have been corrupted during download. Please restart your R session and download the data again."
286+
cli::cli_alert_danger(msg)
286287
return(invisible(NULL))
287288
}
288289

‎r-package/aopdata.Rproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: 621a5134-b223-44e6-b779-b10fcc883866
23

34
RestoreWorkspace: No
45
SaveWorkspace: No

0 commit comments

Comments
 (0)