Skip to content

Commit

Permalink
simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Oct 10, 2023
1 parent 4384573 commit ca7e702
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ setMethod("tags", signature(x="SpatRaster"),
function(x, name=NULL) {
v <- x@cpp$getTags()
m <- matrix(v, ncol=2, byrow=TRUE, dimnames = list(NULL, c("name", "value")))
out <- m[,2]
names(out) <- m[,1]
if (!is.null(name)) {
i <- match(name, m[,1])
m[i,2]
} else {
m
}
out <- out[name]
}
out
}
)


setMethod("tags<-", signature(x="SpatRaster"),
function(x, value) {
if (is.null(value)) {
value <- tags(x)
value <- matrix(x@cpp$getTags(), ncol=2, byrow=TRUE)
value[,2] <- ""
} else if (NCOL(value) == 1) {
value <- strsplit(value, "=")
Expand Down
2 changes: 1 addition & 1 deletion man/tags.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You can set arbitrary metadata to a SpatRaster using "name=value" tags.
}

\value{
SpatRaster (\code{tags<-}), matrix (\code{tags}) or character (\code{tags} and \code{name} is not NULL)
SpatRaster (\code{tags<-}), or named character (\code{tags})
}

\examples{
Expand Down

0 comments on commit ca7e702

Please sign in to comment.