Skip to content

Commit

Permalink
fixes #1406
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Jan 25, 2024
1 parent d557805 commit def5397
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions R/levels.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ setMethod ("set.cats" , "SpatRaster",
if (ncol(value) == 1) {
error("set.cats", "value should have at least two columns")
} else {
if (!is.numeric(value[,1])) {
if (!is.numeric(value[[1]])) {
error("set.cats", "the first column of 'value' must be numeric")
}
value[,1] <- round(value[,1])
if (length(unique(value[,1,drop=TRUE])) != nrow(value)) {
value[,1] <- round(value[[1]])
if (length(unique(value[[1]])) != nrow(value)) {
error("set.cats", "duplicate values (IDs) supplied")
}
}
Expand All @@ -182,10 +182,10 @@ setMethod ("set.cats" , "SpatRaster",
}
}
}
if (any(is.na(value[,1]))) {
if (any(is.na(value[[1]]))) {
error("set.cats", "you cannot associate a category with NA")
}
if (any(table(value[,1]) > 1)) {
if (any(table(value[[1]]) > 1)) {
error("set.cats", "you cannot have duplicate IDs")
}

Expand Down

0 comments on commit def5397

Please sign in to comment.