diff --git a/R/generics.R b/R/generics.R index 77fd52ceb..3e45353e4 100644 --- a/R/generics.R +++ b/R/generics.R @@ -4,9 +4,15 @@ # License GPL v3 setMethod("tags", signature(x="SpatRaster"), - function(x) { + function(x, name=NULL) { v <- x@cpp$getTags() - matrix(v, ncol=2, byrow=TRUE, dimnames = list(NULL, c("name", "value"))) + m <- matrix(v, ncol=2, byrow=TRUE, dimnames = list(NULL, c("name", "value"))) + if (!is.null(name)) { + i <- match(name, m[,1]) + m[i,2] + } else { + m + } } ) diff --git a/man/tags.Rd b/man/tags.Rd index c5c257767..d008613f7 100644 --- a/man/tags.Rd +++ b/man/tags.Rd @@ -6,16 +6,16 @@ \alias{set.tags,SpatRaster-method} -\title{Set or get tags to a SpatRaster} +\title{Set or get tags} \description{ -You can set arbitrary tags to a SpatRaster. Each tag has a name and a value. +You can set arbitrary tags metadata to a SpatRaster. Each tag has a name and a value. } \usage{ \S4method{set.tags}{SpatRaster}(x, name, value) -\S4method{tags}{SpatRaster}(x) +\S4method{tags}{SpatRaster}(x, name=NULL) } \arguments{ @@ -27,7 +27,7 @@ You can set arbitrary tags to a SpatRaster. Each tag has a name and a value. } \value{ -SpatRaster (\code{set.tags}) or matrix (\code{tags}) +SpatRaster (\code{set.tags}), matrix (\code{tags}) or character (\code{tags} and \code{name} is not NULL) } \examples{ @@ -38,6 +38,8 @@ tags(r) r <- set.tags(r, "another_tag", "another_value") tags(r) +tags(r, "two") + # remove one tag r <- set.tags(r, c("one"), c("")) tags(r)