Skip to content

Commit

Permalink
approve_all_dl if session is non-interactive, closes #54
Browse files Browse the repository at this point in the history
  • Loading branch information
jsta committed Jan 22, 2019
1 parent cab1752 commit 0bcce9e
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 14 deletions.
12 changes: 10 additions & 2 deletions R/load.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @param dsn character name of a NHD layer
#' @param file_ext character choice of "shp" for spatial data and
#' "dbf" or "gpkg" for non-spatial. optional
#' @param approve_all_dl logical blanket approval to download all missing data
#' @param approve_all_dl logical blanket approval to download all missing data. Defaults to TRUE if sesson is non-interactive.
#' @param ... arguments passed to sf::st_read
#'
#' @return Spatial simple features object or data frame depending on the dsn
Expand All @@ -29,6 +29,10 @@
#' }
nhd_load <- function(state, dsn, file_ext = NA, approve_all_dl = FALSE, ...){

if(!interactive()){
approve_all_dl = TRUE
}

if(!(file_ext %in% c(NA, "shp", "dbf", "gpkg"))){
stop(paste0("file_ext must be set to either 'shp' or 'dbf'"))
}
Expand Down Expand Up @@ -128,7 +132,7 @@ nhd_load <- function(state, dsn, file_ext = NA, approve_all_dl = FALSE, ...){
#' @param dsn data source name
#' @param file_ext character choice of "shp" for spatial data and
#' "dbf" for non-spatial. optional
#' @param approve_all_dl logical blanket approval to download all missing data
#' @param approve_all_dl logical blanket approval to download all missing data. Defaults to TRUE if sesson is non-interactive
#' @param force_dl logical force a re-download of the requested data
#' @param pretty more minimal pretty printing st_read relative to "quiet"
#' @param ... parameters passed on to sf::st_read
Expand Down Expand Up @@ -172,6 +176,10 @@ nhd_plus_load <- memoise::memoise(function(vpu, component = "NHDSnapshot", dsn,
file_ext = NA, approve_all_dl = FALSE, force_dl = FALSE,
pretty = FALSE, ...){

if(!interactive()){
approve_all_dl = TRUE
}

if(!(file_ext %in% c(NA, "shp", "dbf"))){
stop(paste0("file_ext must be set to either 'shp' or 'dbf'"))
}
Expand Down
18 changes: 15 additions & 3 deletions R/network.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#' @param network sf lines collection. optional. See Details section.
#' @param lakepoly sf polygon. optional. See Details section.
#' @param buffer_dist numeric buffer around lat-lon point in dec. deg.
#' @param lakewise logical. If TRUE, return the terminal reaches of all lakes
#' @param lakewise logical. If TRUE, return the terminal reaches of all lakes.
#' in the stream network rather than a single terminal reach of the focal lake.
#' @param lakesize_threshold numeric above which to count as a lake (ha)
#' @param approve_all_dl logical blanket approval to download all missing data
#' @param lakesize_threshold numeric above which to count as a lake (ha).
#' @param approve_all_dl logical blanket approval to download all missing data. Defaults to TRUE if sesson is non-interactive.
#' @param ... parameters passed on to sf::st_read
#'
#' @export
Expand Down Expand Up @@ -68,6 +68,10 @@ terminal_reaches <- function(lon = NA, lat = NA, buffer_dist = 0.01,
network = NA, lakepoly = NA, lakewise = FALSE,
lakesize_threshold = 4, approve_all_dl = FALSE, ...){

if(!interactive()){
approve_all_dl = TRUE
}

if(all(is.na(network))){
pnt <- st_sfc(st_point(c(lon, lat)))
st_crs(pnt) <- st_crs(nhdR::vpu_shp)
Expand Down Expand Up @@ -185,6 +189,10 @@ terminal_reaches <- function(lon = NA, lat = NA, buffer_dist = 0.01,
leaf_reaches <- function(lon = NA, lat = NA, network = NA,
approve_all_dl = FALSE, ...){

if(!interactive()){
approve_all_dl = TRUE
}

if(all(is.na(network))){
pnt <- sf::st_sfc(sf::st_point(c(lon, lat)))
sf::st_crs(pnt) <- sf::st_crs(nhdR::vpu_shp)
Expand Down Expand Up @@ -268,6 +276,10 @@ extract_network <- function(lon = NA, lat = NA, lines = NA,
buffer_dist = 0.01, maxsteps = 3,
approve_all_dl = FALSE){

if(!interactive()){
approve_all_dl = TRUE
}

if(length(lon) > 1 | length(lat) > 1){
stop("extract_network only accepts a single lon-lat pair.")
}
Expand Down
6 changes: 5 additions & 1 deletion R/query.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param poly sfc polygon. optional
#' @param dsn character data source
#' @param buffer_dist numeric buffer in units of coordinate degrees
#' @param approve_all_dl logical blanket approval to download all missing data
#' @param approve_all_dl logical blanket approval to download all missing data. Defaults to TRUE if sesson is non-interactive.
#' @param ... parameters passed on to sf::st_read
#' @examples \dontrun{
#' library(sf)
Expand Down Expand Up @@ -45,6 +45,10 @@ nhd_plus_query <- function(lon = NA, lat = NA, poly = NA,
dsn, buffer_dist = 0.05, approve_all_dl = FALSE,
...){

if(!interactive()){
approve_all_dl = TRUE
}

if(all(!is.na(c(lon, lat, poly)))){
stop("Must specify either lon and lat or poly but not both.")
}
Expand Down
2 changes: 1 addition & 1 deletion man/extract_network.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/leaf_reaches.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/nhd_load.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/nhd_plus_load.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/nhd_plus_query.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/terminal_reaches.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0bcce9e

Please sign in to comment.