From fcad3e8e434b71e6ec61d59e032944a8dc09c24c Mon Sep 17 00:00:00 2001 From: Andrew Gene Brown Date: Thu, 22 Feb 2024 20:09:33 -0800 Subject: [PATCH] `horizons<-`: make sure short circuit is properly invoked! - affects efficiency in cases where single column is being set or nulled --- R/SoilProfileCollection-setters.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/SoilProfileCollection-setters.R b/R/SoilProfileCollection-setters.R index 82442a28..b262a98a 100644 --- a/R/SoilProfileCollection-setters.R +++ b/R/SoilProfileCollection-setters.R @@ -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.")