Skip to content

Commit 9f8b811

Browse files
committed
Fixed an error that occurred in read_in_flow when importing hillslopes with a single patch. The error caused the neighbors from the patch after the single-patch hillslope to be assigned to the single-patch hillslope, and so on. New code corrects this issue.
1 parent a40fc88 commit 9f8b811

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

R/read_in_flow.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ read_in_flow <- function(input_file, df = FALSE) {
4444
nbr_p <- split(neighbors$Number, f = n_ind2) # neighbor numbers (NOT PATCH NUMBERS)
4545
nbr_g <- split(neighbors$Gamma_i, f = n_ind2) # gammas
4646

47+
# Identify patches with no neighbors and add them to neighbors lists
48+
no_neighbors <- flw_df$Number[!flw_df$Number %in% unique(n_ind2)]
49+
for (i in no_neighbors){
50+
nbr_p <- append(nbr_p, list(vector(mode="numeric", length=0)), after = i-1) # To match the syntax in make_flow_list, patches with no neighbors need be numeric(0)
51+
names(nbr_p)[i] <- i
52+
nbr_g <- append(nbr_g, list(vector(mode="numeric", length=0)), after = i-1) # To match the syntax in make_flow_list, patches with no neighbors need be numeric(0)
53+
names(nbr_g)[i] <- i
54+
}
55+
4756
list_append <- function(X, Y, Z) { # to append to the list, but keep the appended vector together, and not split those elements up
4857
X[[Z]] <- Y
4958
return(X)

0 commit comments

Comments
 (0)