Skip to content

Commit

Permalink
horizons<-: make sure short circuit is properly invoked!
Browse files Browse the repository at this point in the history
 - affects efficiency in cases where single column is being set or nulled
  • Loading branch information
brownag committed Feb 23, 2024
1 parent 6a8020c commit fcad3e8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/SoilProfileCollection-setters.R
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,10 @@ setReplaceMethod("horizons", signature(object = "SoilProfileCollection"),
if (!inherits(value, "data.frame"))
stop("new horizon data input value must inherit from data.frame", call. = FALSE)

# allow short-circuit
if (all(colnames(value) %in% horizonNames(object)) &
all(c(idn, hdn, hzd) %in% colnames(value)) &
# allow short-circuit (handles NULL and non-op without going thru merge())
if ((all(horizonNames(object) %in% colnames(value)) ||
all(colnames(value) %in% horizonNames(object))) &&
all(c(idn, hdn, hzd) %in% colnames(value)) &&
nrow(value) == nrow(object)) {
if (!all(value[[idn]] %in% profile_id(object))) {
message("Some profile IDs in input data are not present in object and no new columns to merge. Doing nothing.")
Expand Down

0 comments on commit fcad3e8

Please sign in to comment.