Last active
September 29, 2020 13:17
-
-
Save dholstius/8aa00e7e78570be9e16b0a37bd789395 to your computer and use it in GitHub Desktop.
lists of RasterLayers behaving weirdly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# If I wrap a single RasterLayer in a list, I can extract it | |
# with .[[1]] but not with unlist(). | |
# | |
# This example just uses a single `RasterLayer` to make the point. | |
# The broader problem (for me) is that it seems to be precluding the | |
# possibility of using `purrr::map2()` to combine lists of RasterLayers | |
# in various ways. | |
# | |
library(raster) | |
# Canned example | |
logo <- raster(system.file("external/rlogo.grd", package="raster")) | |
# Wrap it in a list | |
x <- list(logo) | |
# Works as expected | |
x[[1]] | |
# Mystery: still a list ... | |
unlist(x) | |
# TRUE --- but why? | |
identical(x, unlist(x)) | |
# For reference | |
sessionInfo() | |
# R version 3.6.2 (2019-12-12) | |
# Platform: x86_64-apple-darwin15.6.0 (64-bit) | |
# Running under: macOS Catalina 10.15.6 | |
# | |
# Matrix products: default | |
# BLAS: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib | |
# LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib | |
# | |
# locale: | |
# [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 | |
# | |
# attached base packages: | |
# [1] stats graphics grDevices utils datasets methods base | |
# | |
# loaded via a namespace (and not attached): | |
# [1] compiler_3.6.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment