Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Oct 10, 2023
1 parent 1fabce1 commit 5ce1b3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 8 additions & 2 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
)

Expand Down
10 changes: 6 additions & 4 deletions man/tags.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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)
Expand Down

0 comments on commit 5ce1b3f

Please sign in to comment.