Skip to content

Commit

Permalink
construct remote urls accounting for multimatching, closes #58
Browse files Browse the repository at this point in the history
  • Loading branch information
jsta committed May 1, 2019
1 parent 8b6dbc1 commit 114c2d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
1 change: 0 additions & 1 deletion R/load.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ nhd_plus_load <- memoise::memoise(function(vpu, component = "NHDSnapshot", dsn,
}

nhd_plus_load_vpu <- function(vpu, component, dsn, pretty, ...){

vpu_path <- list.files(file.path(nhd_path(), "NHDPlus"),
include.dirs = TRUE, full.names = TRUE)

Expand Down
13 changes: 10 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,16 @@ get_plus_remotepath <- function(vpu, component = "NHDSnapshot"){
}

res <- rvest::html_attrs(rvest::html_nodes(xml2::read_html(baseurl), "a"))
res <- unlist(res[grep(component, res)])
res <- res[!(seq_len(length(res)) %in% c(grep("FGDB", res), grep(".pdf", res)))][1]
res

if(vpu == "National"){
res <- unlist(res[grep(component, res)])
}else{
res <- unlist(res[grep(paste0(vpu, "_", component), res)])
}

res <- res[!(seq_len(length(res)) %in%
c(grep("FGDB", res), grep(".pdf", res)))]
res[1]
}

is_spatial <- function(filename){
Expand Down
15 changes: 9 additions & 6 deletions tests/testthat/test-get.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ test_that("remote urls are constructed correctly", {
skip_on_cran()
skip_on_travis()

expect_true(RCurl::url.exists(
get_plus_remotepath(4, component = "NHDSnapshot")))

expect_true(RCurl::url.exists(
get_plus_remotepath("National", component = "V1_To_V2_Crosswalk")
))
expect_true(
RCurl::url.exists(
nhdR:::get_plus_remotepath(4, component = "NHDSnapshot"))
)

expect_true(
RCurl::url.exists(
nhdR:::get_plus_remotepath("National", component = "V1_To_V2_Crosswalk"))
)


})
Expand Down

0 comments on commit 114c2d8

Please sign in to comment.