Skip to content

Commit 7439c40

Browse files
committed
deal with missing x,y in csv
1 parent f79d3c8 commit 7439c40

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

R/walk_pages.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ get_csv <- function(req, limit) {
137137

138138
if (httr2::resp_has_body(resp)) {
139139
return_list <- httr2::resp_body_string(resp)
140-
df <- data.table::fread(input = return_list, data.table = FALSE)
140+
df <- data.table::fread(
141+
input = return_list,
142+
data.table = FALSE,
143+
colClasses = "text"
144+
)
141145

142146
included_num_cols <- names(df)[names(df) %in% num_cols]
143147

@@ -148,8 +152,10 @@ get_csv <- function(req, limit) {
148152
if (skip_geo) {
149153
df <- df[, names(df)[!names(df) %in% c("x", "y")]]
150154
} else {
151-
df <- sf::st_as_sf(df, coords = c("x", "y"))
152-
sf::st_crs(df) <- 4269
155+
if (all(c("x", "y") %in% names(df))) {
156+
df <- sf::st_as_sf(df, coords = c("x", "y"))
157+
sf::st_crs(df) <- 4269
158+
}
153159
}
154160

155161
if (nrow(df) == limit) {

tests/testthat/tests_userFriendly_fxns.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,18 @@ test_that("bad_properties", {
585585
time = c("2021-01-01", "2022-01-01"),
586586
properties = c("value", "time", "blah")
587587
))
588+
589+
# No paging
590+
dv_data_quick <- read_waterdata_daily(
591+
monitoring_location_id = site,
592+
parameter_code = "00060",
593+
no_paging = TRUE
594+
)
595+
596+
expect_type(dv_data_quick$parameter_code, "character")
597+
expect_is(dv_data_quick$time, "Date")
598+
expect_equal(dv_data_quick$parameter_code[1], "00060")
599+
588600
# Empty result:
589601
expect_message(read_waterdata_daily(
590602
monitoring_location_id = "USGS-02238500",

0 commit comments

Comments
 (0)