R Under development (unstable) (2024-11-06 r87293 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > suppressPackageStartupMessages(library(stars)) > > if (require(dplyr, quietly = TRUE)) { + tif = system.file("tif/L7_ETMs.tif", package = "stars") + x <- read_stars(tif) + (y <- x %>% select(L7_ETMs.tif)) + (y <- x %>% filter(band > 2)) + (z <- x %>% mutate(foo = 2* L7_ETMs.tif)) + x %>% pull(L7_ETMs.tif) %>% class() + x %>% filter(x > 289900) + x %>% slice("x", 50:100) + + suppressPackageStartupMessages(library(ggplot2)) + ggplot() + geom_stars(data = x) + coord_equal() + facet_wrap(~band) + ggplot() + geom_stars(data = x[,c(1:50,52:100),c(1:45, 50:60)]) + + coord_equal() + ggplot() + geom_stars(data = x[,1:10,1:10,1:2], sf = TRUE) + facet_wrap(~band) + + + # see https://github.com/r-spatial/stars/issues/539 : + x <- read_stars(system.file("tif/L7_ETMs.tif", package = "stars")) + y <- transmute(x, L7_ETMs.tif = units::set_units(L7_ETMs.tif, degree_C)) # same as x but with units + + x - slice(x, 'band', 1) # runs as expected, recycling the second object + try(y - slice(x, 'band', 1)) # fails as expected because x is unitless + try(x - slice(y, 'band', 1)) # fails as expected + y - slice(y, 'band', 1) # runs as expected + } Attaching package: 'dplyr' The following objects are masked from 'package:stats': filter, lag The following objects are masked from 'package:base': intersect, setdiff, setequal, union Error in Ops.units(X[[i]], ...) : both operands of the expression should be "units" objects Error in Ops.units(X[[i]], ...) : both operands of the expression should be "units" objects stars object with 3 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. L7_ETMs.tif [°C] -184 -19 -8 -10.2353 0 131 dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA > > proc.time() user system elapsed 1.92 0.40 2.31