From ca7e702d335a8ec1260e7846bc833a81180f0f08 Mon Sep 17 00:00:00 2001 From: rhijmans Date: Tue, 10 Oct 2023 06:00:02 -0700 Subject: [PATCH] simpler --- R/generics.R | 13 +++++++------ man/tags.Rd | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/R/generics.R b/R/generics.R index c02b01ce9..dccf26dd9 100644 --- a/R/generics.R +++ b/R/generics.R @@ -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, "=") diff --git a/man/tags.Rd b/man/tags.Rd index 4235d41d3..b1ac8299d 100644 --- a/man/tags.Rd +++ b/man/tags.Rd @@ -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{