Derived class loss of projection
bart1 opened this issue · 4 comments
bart1 commented
While updating the move package I encountered the following strange behavior, when creating a derived class on initiation the projection is lost. As far as I know this used to work:
require(raster)
#> Loading required package: raster
#> Loading required package: sp
setClass(
Class = "UD", contains = c("RasterLayer"),
representation = representation(method = "character"),
prototype = prototype(
method = as.character()
),
validity = function(object) {
return(TRUE)
}
)
r<-raster()
ud<-new("UD", r, method="asdf")
proj4string(ud)
#> [1] NA
proj4string(r)
#> [1] "+proj=longlat +datum=WGS84 +no_defs"
ud
#> class : UD
#> dimensions : 180, 360, 64800 (nrow, ncol, ncell)
#> resolution : 1, 1 (x, y)
#> extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
#> crs : NA
r
#> class : RasterLayer
#> dimensions : 180, 360, 64800 (nrow, ncol, ncell)
#> resolution : 1, 1 (x, y)
#> extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
#> crs : +proj=longlat +datum=WGS84 +no_defs
sessionInfo()
#> R version 4.2.2 Patched (2022-11-10 r83330)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.5 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=nl_NL.UTF-8 LC_COLLATE=en_US.UTF-8
#> [5] LC_MONETARY=nl_NL.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=nl_NL.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] raster_3.6-13 sp_1.5-1
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_1.0.9 rstudioapi_0.14 knitr_1.41 magrittr_2.0.3
#> [5] lattice_0.20-45 R.cache_0.16.0 rlang_1.0.6 fastmap_1.1.0
#> [9] stringr_1.5.0 styler_1.8.1 highr_0.10 tools_4.2.2
#> [13] rgdal_1.6-3 grid_4.2.2 xfun_0.36 R.oo_1.25.0
#> [17] terra_1.6-47 cli_3.5.0 withr_2.5.0 htmltools_0.5.4
#> [21] yaml_2.3.6 digest_0.6.31 lifecycle_1.0.3 purrr_1.0.0
#> [25] codetools_0.2-18 vctrs_0.5.1 R.utils_2.12.2 fs_1.5.2
#> [29] glue_1.6.2 evaluate_0.19 rmarkdown_2.19 reprex_2.0.2
#> [33] stringi_1.7.8 compiler_4.2.2 R.methodsS3_1.8.2
Created on 2023-01-11 with reprex v2.0.2
rhijmans commented
Thanks. With the change I made I get
ud<-new("UD", r, method="asdf")
proj4string(ud)
#[1] "+proj=longlat +datum=WGS84 +no_defs"
I will do a reverse dependency check to see if it breaks something else.
bart1 commented
Thanks! I quickly checked and it also works for me, any chance you will release this to CRAN soon? then I would not have to implement a work around
rhijmans commented
Yes, of course, this is on me, and I will get it to CRAN in a couple of days.
bart1 commented
move
is now on cran without errors