From c39ecf1d158fd8affdc8f11e2499850b18009c7f Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Wed, 30 Sep 2020 10:25:41 -0700 Subject: [PATCH] rebuildSPC: enforce aqp_df_class; possibly changed by aqp_df_class<- #157 --- R/Class-SoilProfileCollection.R | 13 +++++++++++++ R/rebuildSPC.R | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/R/Class-SoilProfileCollection.R b/R/Class-SoilProfileCollection.R index 15173119d..2b55ed9b8 100644 --- a/R/Class-SoilProfileCollection.R +++ b/R/Class-SoilProfileCollection.R @@ -1316,6 +1316,19 @@ setMethod(f = 'aqp_df_class', signature(object = 'SoilProfileCollection'), return(u) }) +if (!isGeneric("aqp_df_class<-")) + setGeneric("aqp_df_class<-", function(object, ...) + standardGeneric("aqp_df_class<-")) +#' @param value "data.frame", "data.table" or "tibble" +#' @rdname aqp_df_class +setReplaceMethod("aqp_df_class", signature(object = "SoilProfileCollection"), + function(object, value) { + if (!value %in% c('data.frame',"data.table","tibble")) + stop("aqp_df_class metadata entry must be data.frame, data.table or tibble", + call.=FALSE) + metadata(object)$aqp_df_class <- value + return(object) + }) #' Get depth units from metadata #' diff --git a/R/rebuildSPC.R b/R/rebuildSPC.R index b8ca088bb..fc7c38f1f 100644 --- a/R/rebuildSPC.R +++ b/R/rebuildSPC.R @@ -6,7 +6,7 @@ rebuildSPC <- function(x) { x.list <- suppressWarnings(as(x, 'list')) # seed object for new SPC - res <- x.list$horizons + res <- .as.data.frame.aqp(x.list$horizons, aqp_df_class(x)) # init SPC from pieces # note: using depths<- because it will generate a horizon ID