Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Dec 19, 2024
1 parent d077a38 commit 6d2046d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
- `mosaic` sometimes crashed R [#1524](https://github.com/rspatial/terra/issues/1524) by John Baums, Dave Klinges, and Hugh Graham.
- `spatSample` ignored argument "exp" when taking a random sample with na.rm=TRUE on a large raster [#1437](https://github.com/rspatial/terra/issues/1437) by Babak Naimi
- `split<SpatVector,SpatVector>` did not work properly [#1619](https://github.com/rspatial/terra/issues/1619) by Michael Sumner
- `autocor` improved handling of NA cells for global Moran computation [#1992](https://github.com/rspatial/terra/issues/1592) by Nicholas Berryman

## enhancements

- `plot<SpatVector>` now uses the same default viridis color palette as `plot<SpatRaster>` [#1670](https://github.com/rspatial/terra/issues/1670) by Márcia Barbosa
- `relate` now accepts relation="equals" [#1672](https://github.com/rspatial/terra/issues/1672) by Krzysztof Dyba
- `init` accepts additional arguments for function "fun"

## new

Expand Down
8 changes: 4 additions & 4 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


setMethod("init", signature(x="SpatRaster"),
function(x, fun, filename="", ...) {
opt <- spatOptions(filename, ...)
function(x, fun, ..., filename="", wopt=list()) {
opt <- spatOptions(filename, wopt)
x <- rast(x)
if (is.character(fun)) {
x <- rast(x, 1)
Expand All @@ -25,10 +25,10 @@ setMethod("init", signature(x="SpatRaster"),
messages(x, "init")
} else {
nc <- ncol(x) * nlyr(x)
b <- writeStart(x, filename, sources=sources(x), ...)
b <- writeStart(x, filename, sources=sources(x), opt)
for (i in 1:b$n) {
n <- b$nrows[i] * nc;
r <- fun(n)
r <- fun(n, ...)
if (length(r) != n) {
error("init","the number of values returned by 'fun' is not correct")
}
Expand Down
5 changes: 3 additions & 2 deletions man/init.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ Create a SpatRaster with values reflecting a cell property: "x", "y", "col", "ro
}

\usage{
\S4method{init}{SpatRaster}(x, fun, filename="", ...)
\S4method{init}{SpatRaster}(x, fun, ..., filename="", wopt=list())
}

\arguments{
\item{x}{SpatRaster}
\item{fun}{function to be applied. This must be a either single number, multiple numbers, a function, or one of a set of known character values. A function must take the number of cells as a single argument to return a vector of values with a length equal to the number of cells, such as \code{fun=runif}. Allowed character values are "x", "y", "row", "col", "cell", and "chess" to get the x or y coordinate, row, col or cell number or a chessboard pattern (alternating 0 and 1 values)}
\code{...}{additional arguments passed to \code{fun}}
\item{filename}{character. Output filename}
\item{...}{additional arguments for writing files as in \code{\link{writeRaster}}}
\item{wopt}{additional arguments for writing files as in \code{\link{writeRaster}}}
}


Expand Down

0 comments on commit 6d2046d

Please sign in to comment.