Skip to content

Commit

Permalink
check usage of return #12
Browse files Browse the repository at this point in the history
  • Loading branch information
dblodgett-usgs committed Sep 11, 2023
1 parent b7ee364 commit 6bd0877
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions R/accumulate_downstream.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ required_atts_accumulate <- c(id, toid)
#'
#' plot(x['totDASqKM'], lwd = x$totDASqKM / 50)
accumulate_downstream <- function(x, var) {
if(!var %in% names(x)) stop(paste(var, "must be in x"))
if(!var %in% names(x)) stop(var, " must be in x")

UseMethod("accumulate_downstream")
}
Expand Down Expand Up @@ -58,5 +58,5 @@ accumulate_downstream.hy <- function(x, var) {

x <- distinct(left_join(cat_order, x, by = "id"))

return(x[[var]])
x[[var]]
}
2 changes: 1 addition & 1 deletion R/add_divergence.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ required_atts_add_divergence <- c("id", "fromnode", "tonode")
#' name to use is chosen 1) if there is only one upstream flowline with a name
#' 2) if one of the upstream flowlines with a name matches the downstream line,
#' 3) if one of the upstream flowlines is of a "major" type and others are not,
#' and 4) the smallest id value otherwise.
#' and, 4) if no criteria exist to select one, the smallest id value otherwise.
#'
#' @name add_divergence
#' @export
Expand Down
8 changes: 3 additions & 5 deletions R/add_levelpaths.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,9 @@ add_levelpaths.hy <- function(x, name_attribute, weight_attribute,
x <- select(x, all_of(c(id, toid, levelpath_outlet_id, topo_sort, levelpath)),
!all_of(c("done", "lp_name_attribute", "lp_weight_attribute", "ind", "toind")))

x <- left_join(x, select(extra, -any_of(c("levelpath_outlet_id", "topo_sort", "levelpath"))),
by = id)
left_join(x, select(extra, -any_of(c("levelpath_outlet_id", "topo_sort", "levelpath"))),
by = id)

return(x)
}

par_get_path <- function(outlet, x_in, from_ind, status, wat) {
Expand Down Expand Up @@ -248,8 +247,7 @@ get_path <- function(x, tailid, from_ind, status, wat) {

}


return(tracker[!is.na(tracker)])
tracker[!is.na(tracker)]
}

reweight <- function(x, ..., override_factor, nat, wat) {
Expand Down
2 changes: 1 addition & 1 deletion R/add_pathlength.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ add_pathlength.hy <- function(x) {
}
}

return(left_join(orig_order, x, by = id))
left_join(orig_order, x, by = id)
}
2 changes: 1 addition & 1 deletion R/add_pfafstetter.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,5 @@ cleanup_pfaf <- function(pfaf) {
floor(pfaf[, (i + 1)][is.na(pfaf[, i, drop = TRUE]), ] / 10)
}

return(pfaf)
pfaf
}
4 changes: 2 additions & 2 deletions R/align_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ align_names <- function(x) {

names(x)[switch_back] <- orig_names[switch_back]

return(x)
x

}

Expand Down Expand Up @@ -129,6 +129,6 @@ hydroloom_names <- function(x = NULL, clear = FALSE) {

assign("hydroloom_name_map", hl, envir = hydroloom_env)

return(hl)
hl

}
2 changes: 1 addition & 1 deletion R/get_hydro_location.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ get_hydro_location_single <- function(x) {

new <- interp_meas(new_m, coords$X[nds], coords$Y[nds], coords$X[nus], coords$Y[nus])

return(st_sfc(st_point(c(new[[1]], new[[2]])), crs = st_crs(x[[2]])))
st_sfc(st_point(c(new[[1]], new[[2]])), crs = st_crs(x[[2]]))
}

interp_meas <- function(m, x1, y1, x2, y2) {
Expand Down
4 changes: 2 additions & 2 deletions R/index_points_to_lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ matcher <- function(coords, points, search_radius, max_matches = 1) {
ungroup() |>
as.data.frame()

return(matched)
matched
}

check_search_radius <- function(search_radius, points) {
Expand Down Expand Up @@ -338,7 +338,7 @@ index_points_to_lines.hy <- function(x, points,
by = c("node" = "index")) |>
select(all_of(select_vec2))

return(matched)
matched
}

#' @title Index Points to Waterbodies
Expand Down
2 changes: 1 addition & 1 deletion R/make_fromids.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ make_fromids <- function(index_ids, return_list = FALSE) {
if(return_list) return(list(froms = froms_m, lengths = froms_l,
froms_list = froms))

return(list(froms = froms_m, lengths = froms_l))
list(froms = froms_m, lengths = froms_l)

}

Expand Down
2 changes: 1 addition & 1 deletion R/make_index_ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ format_index_ids <- function(g, return_list = FALSE) {
if(return_list) return(list(to = to_m, lengths = to_l,
to_list = g))

return(list(to = to_m, lengths = to_l))
list(to = to_m, lengths = to_l)

}
20 changes: 10 additions & 10 deletions R/navigation_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ get_UT <- function(x, id, distance) {

x <- filter(x, .data$id %in% all)

return(filter(x, .data$pathlength_km <= stop_pathlength_km)$id)
filter(x, .data$pathlength_km <= stop_pathlength_km)$id
} else {
return(all)
all
}
}

Expand All @@ -160,9 +160,9 @@ private_get_UT <- function(x, id) {
trib_id <- filter(x, levelpath %in% trib_lpid)$id

if (length(trib_id) > 0) {
return(c(full_main$id, private_get_UT(x, trib_id)))
c(full_main$id, private_get_UT(x, trib_id))
} else {
return(full_main$id)
full_main$id
}
}

Expand All @@ -187,7 +187,7 @@ get_UM <- function(x, id, distance = NULL) {

}

return(main_us$id)
main_us$id
}

get_DM <- function(x, id, distance = NULL) {
Expand All @@ -210,7 +210,7 @@ get_DM <- function(x, id, distance = NULL) {
filter(id %in% main_ds$id, (pathlength_km + length_km) >= stop_pathlength_km)
}

return(main_ds$id)
main_ds$id
}


Expand Down Expand Up @@ -246,7 +246,7 @@ private_get_DM <- function(x, id) {
}
}

return(select(ds_main, id, topo_sort))
select(ds_main, id, topo_sort)
}

get_DD <- function(x, id, distance = NULL) {
Expand All @@ -267,9 +267,9 @@ get_DD <- function(x, id, distance = NULL) {
if (!is.null(distance)) {
x <- filter(x, id %in% unique(all))

return(filter(x, (pathlength_km + length_km) >= stop_pathlength_km)$id)
filter(x, (pathlength_km + length_km) >= stop_pathlength_km)$id
} else {
return(unique(all))
unique(all)
}
}

Expand Down Expand Up @@ -311,7 +311,7 @@ private_get_DD <- function(x, id, stop_pathlength_km = 0) {

c(ds_main$id, private_get_DD(x, ds_id, stop_pathlength_km))
} else {
return(ds_main$id)
ds_main$id
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/sort_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,5 @@ sort_network.hy <- function(x, split = FALSE, outlets = NULL) {

x <- put_hyg(x, hy_g)

return(x)
x
}
2 changes: 1 addition & 1 deletion man/add_divergence.Rd

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

0 comments on commit 6bd0877

Please sign in to comment.