Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terra::coltab() does not accept data frame list on v1.7-46 #1280

Closed
dieghernan opened this issue Sep 15, 2023 · 1 comment
Closed

terra::coltab() does not accept data frame list on v1.7-46 #1280

dieghernan opened this issue Sep 15, 2023 · 1 comment

Comments

@dieghernan
Copy link

Hi @rhijmans

I am planning to add support on tidyterra for SpatRaster with coltab. However, after the latest release on CRAN (v1.7.46) I see a change of behaviour.

Before, terra::coltab() accepted a list of data frame (as per the docs: ...you can also supply a list of such data.frames to set a color table to all layers) but on the latest release this approach does not work any more, and a list of data frames throws an error, see:

library(terra)
#> terra 1.7.46
r <- rast(ncols = 3, nrows = 2, vals = 1:6)
coltb <- data.frame(value = 1:6, col = rainbow(6, end = .9))

r_copy <- r
coltab(r_copy) <- coltb

has.colors(r_copy)
#> [1] TRUE

# Try to re-set colors:
# note that coltab(r) <- coltab(r_copy) does not work any more

# I can't use the output

mycoltab <- coltab(r_copy)

class(mycoltab)
#> [1] "list"
mycoltab
#> [[1]]
#>   values red green blue alpha
#> 1      1 255     0    0   255
#> 2      2 235   255    0   255
#> 3      3   0   255   41   255
#> 4      4   0   194  255   255
#> 5      5  82     0  255   255
#> 6      6 255     0  153   255


try(coltab(r) <- mycoltab)
#> Error : [coltab<-] cannot set these values

has.colors(r)
#> [1] FALSE

# Need to unlist the coltab
class(mycoltab[[1]])
#> [1] "data.frame"

coltab(r) <- mycoltab[[1]]

has.colors(r)
#> [1] TRUE

Created on 2023-09-15 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.1 (2023-06-16 ucrt)
#>  os       Windows 11 x64 (build 22621)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  Spanish_Spain.utf8
#>  ctype    Spanish_Spain.utf8
#>  tz       Europe/Madrid
#>  date     2023-09-15
#>  pandoc   3.1.1 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.1   2023-03-23 [1] CRAN (R 4.3.0)
#>  codetools     0.2-19  2023-02-01 [2] CRAN (R 4.3.1)
#>  digest        0.6.33  2023-07-07 [1] CRAN (R 4.3.1)
#>  evaluate      0.21    2023-05-05 [1] CRAN (R 4.3.0)
#>  fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.3.0)
#>  fs            1.6.3   2023-07-20 [1] CRAN (R 4.3.1)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.6   2023-08-10 [1] CRAN (R 4.3.1)
#>  knitr         1.44    2023-09-11 [1] CRAN (R 4.3.1)
#>  lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.3.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.3.0)
#>  purrr         1.0.2   2023-08-10 [1] CRAN (R 4.3.1)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.3.0)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.3.0)
#>  R.oo          1.25.0  2022-06-12 [1] CRAN (R 4.3.0)
#>  R.utils       2.12.2  2022-11-11 [1] CRAN (R 4.3.0)
#>  Rcpp          1.0.11  2023-07-06 [1] CRAN (R 4.3.1)
#>  reprex        2.0.2   2022-08-17 [1] CRAN (R 4.3.0)
#>  rlang         1.1.1   2023-04-28 [1] CRAN (R 4.3.0)
#>  rmarkdown     2.24    2023-08-14 [1] CRAN (R 4.3.1)
#>  rstudioapi    0.15.0  2023-07-07 [1] CRAN (R 4.3.1)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.3.0)
#>  styler        1.10.2  2023-08-29 [1] CRAN (R 4.3.1)
#>  terra       * 1.7-46  2023-09-06 [1] CRAN (R 4.3.1)
#>  vctrs         0.6.3   2023-06-14 [1] CRAN (R 4.3.1)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.3.0)
#>  xfun          0.40    2023-08-09 [1] CRAN (R 4.3.1)
#>  yaml          2.3.7   2023-01-23 [1] CRAN (R 4.3.0)
#> 
#>  [1] C:/Users/diego/AppData/Local/R/win-library/4.3
#>  [2] C:/Program Files/R/R-4.3.1/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@rhijmans
Copy link
Member

Thank you for reporting this regression. I believe it has been fixed now.

library(terra)
r <- rast(ncols = 3, nrows = 2, vals = 1:6)
tb <- data.frame(value = 1:6, col = rainbow(6, end = .9))
x <- r
coltab(r) <- tb
coltab(x) <- coltab(r)
coltab(x)[[1]]

#  values red green blue alpha
#1      1 255     0    0   255
#2      2 235   255    0   255
#3      3   0   255   41   255
#4      4   0   194  255   255
#5      5  82     0  255   255
#6      6 255     0  153   255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants