Skip to content

Commit 4a642b0

Browse files
committed
Fixes DOI-USGS#862
1 parent dcbef26 commit 4a642b0

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

R/rejigger_cols.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,5 @@ cleanup_cols <- function(df, service){
8585
attr(df$last_modified, "tzone") <- "UTC"
8686
}
8787

88-
if("value" %in% names(df)){
89-
df$value <- as.numeric(df$value)
90-
}
91-
92-
if("contributing_drainage_area" %in% names(df)){
93-
df$contributing_drainage_area <- as.numeric(df$contributing_drainage_area)
94-
}
95-
96-
if("drainage_area" %in% names(df)){
97-
df$drainage_area <- as.numeric(df$drainage_area)
98-
}
99-
10088
df
10189
}

R/sysdata.rda

132 Bytes
Binary file not shown.

R/walk_pages.R

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ get_resp_data <- function(resp) {
3838
use_sf <- !grepl("skipGeometry=true", resp$url, ignore.case = TRUE)
3939
return_df <- sf::read_sf(httr2::resp_body_string(resp))
4040

41+
included_num_cols <- names(return_df)[names(return_df) %in% num_cols]
42+
43+
if(!all(sapply(sf::st_drop_geometry(return_df[,included_num_cols]), is.numeric))){
44+
return_df[, included_num_cols] <- lapply(sf::st_drop_geometry(return_df[, included_num_cols]), as.numeric)
45+
}
46+
4147
if(!use_sf){
4248
return_df <- sf::st_drop_geometry(return_df)
4349
if("AsGeoJSON(geometry)" %in% names(return_df)){
@@ -106,7 +112,15 @@ get_csv <- function(req, limit){
106112

107113
if(httr2::resp_has_body(resp)){
108114
return_list <- httr2::resp_body_string(resp)
109-
df <- data.table::fread(input = return_list, data.table = FALSE)
115+
df <- data.table::fread(input = return_list,
116+
data.table = FALSE)
117+
118+
included_num_cols <- names(df)[names(df) %in% num_cols]
119+
120+
if(!all(sapply(df[,included_num_cols], is.numeric))){
121+
df[, included_num_cols] <- lapply(df[, included_num_cols], as.numeric)
122+
}
123+
110124
if(skip_geo){
111125
df <- df[, names(df)[!names(df) %in% c("x", "y")]]
112126
} else {

0 commit comments

Comments
 (0)