Skip to content

Commit

Permalink
Update Utilities.R
Browse files Browse the repository at this point in the history
rearranged code related to bug fix for TADA_FindNearbySites
  • Loading branch information
hillarymarler committed Jan 15, 2025
1 parent bc81de9 commit a53c364
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions R/Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,24 @@ TADA_FindNearbySites <- function(.data, dist_buffer = 100,
dplyr::ungroup() %>%
dplyr::filter(!is.na(NHD.nhdplusid))

if (nrow(data_unique_mls == 0)) { # #if no groups, give a TADA.NearbySiteGroup column filled with
# "No nearby sites"
print("TADA_FindNearbySites: No nearby sites detected using input buffer distance. Columns for TADA.NearbySitesFlag and TADA.NearbySiteGroup added for tracking purposes.")

.data <- .data %>%
dplyr::mutate(
TADA.NearbySites.Flag = "No nearby sites detected using input buffer distance.",
TADA.NearbySiteGroup = NA
)

rm(data_unique_mls, nhd_catchments)

return(.data)
}

# check to see if any site groups are found
if(nrow(data_unique_mls) > 1) {

# remove intermediate object
rm(nhd_catchments)

Expand Down Expand Up @@ -980,9 +998,6 @@ TADA_FindNearbySites <- function(.data, dist_buffer = 100,
dplyr::mutate(df_number = .y))

rm(find_groups, binary.mats)

# check to see if any site groups are found
if(length(site.groups.list) > 0) {

# create df of all groups and create unique id for each group
combined.group.df <- dplyr::bind_rows(site.groups.list) %>%
Expand Down Expand Up @@ -1328,19 +1343,6 @@ TADA_FindNearbySites <- function(.data, dist_buffer = 100,
# return TADA df with added columns for tracking
return(.data)
}

if (length(site.groups.list == 0)) { # #if no groups, give a TADA.NearbySiteGroup column filled with
# "No nearby sites"
print("TADA_FindNearbySites: No nearby sites detected using input buffer distance. Columns for TADA.NearbySitesFlag and TADA.NearbySiteGroup added for tracking purposes.")

.data <- .data %>%
dplyr::mutate(
TADA.NearbySites.Flag = "No nearby sites detected using input buffer distance.",
TADA.NearbySiteGroup = NA
)

return(.data)
}
}


Expand Down

0 comments on commit a53c364

Please sign in to comment.