Skip to content

Commit

Permalink
fix for cases where only top depths are out of order #137
Browse files Browse the repository at this point in the history
  • Loading branch information
brownag committed Jul 11, 2020
1 parent 6ab3b63 commit 98595ae
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions R/SoilProfileCollection-setters.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,19 @@ setReplaceMethod("depths", "data.frame",
stringsAsFactors = FALSE), class(data)[1])
names(nusite) <- nm[1]

usortid <- .coalesce.idx(sort(data[[nm[1]]]))
iddata <- data[[nm[1]]]
tdep <- data[[depthcols[1]]]

if (any(nusite[[nm[1]]] != usortid)) {
usortid <- .coalesce.idx(sort(iddata))
hsorttdep <- all(data[order(iddata, tdep),][[depthcols[1]]] == tdep)

if (any(nusite[[nm[1]]] != usortid) | !hsorttdep) {
message("unsorted input data will be ordered by profile ID and top depth")

# reorder based on site ID and top depth column
## note: forced character sort on ID -- need to impose some order to check depths

data <- data[order(as.character(data[[nm[1]]]), data[[depthcols[1]]]),]
data <- data[order(as.character(data[[nm[1]]]), tdep),]
nusite[[nm[1]]] <- .coalesce.idx(data[[nm[1]]])
}

Expand Down

0 comments on commit 98595ae

Please sign in to comment.