terra icon indicating copy to clipboard operation
terra copied to clipboard

Minimal code to generate "#> Error in x$.self$finalize() : attempt to apply non-function"

Open charliejhadley opened this issue 4 years ago • 4 comments

I think this is a minimal code sample to generate this currently mysterious (https://github.com/rspatial/terra/issues/165#issuecomment-811446604) error:

Error in x$.self$finalize() : attempt to apply non-function

I'm able to generate this message on macOS, Windows and Linux:

Windows

library(terra)
#> terra version 1.2.10
# remotes::install_github("geocompr/geocompkg")
library(spDataLarge)
nz_elev <- rast(nz_elev)
plot(nz_elev)
# Error in (function (x)  : attempt to apply non-function
# Error in x$.self$finalize() : attempt to apply non-function
# Error in x$.self$finalize() : attempt to apply non-function
# Error in x$.self$finalize() : attempt to apply non-function
# Error in (function (x)  : attempt to apply non-function
sessionInfo()
#> R version 4.0.5 (2021-03-31)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19042)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_United Kingdom.1252 
#> [2] LC_CTYPE=English_United Kingdom.1252   
#> [3] LC_MONETARY=English_United Kingdom.1252
#> [4] LC_NUMERIC=C                           
#> [5] LC_TIME=English_United Kingdom.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] spDataLarge_0.5.1 terra_1.2-10     
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.6        rstudioapi_0.13   xml2_1.3.2        knitr_1.33       
#>  [5] raster_3.4-10     magrittr_2.0.1    lattice_0.20-41   R6_2.5.0         
#>  [9] rlang_0.4.10      httr_1.4.2        stringr_1.4.0     highr_0.9        
#> [13] tools_4.0.5       grid_4.0.5        xfun_0.22         cli_2.5.0        
#> [17] withr_2.4.2       htmltools_0.5.1.1 yaml_2.2.1        digest_0.6.27    
#> [21] fs_1.5.0          ps_1.6.0          codetools_0.2-18  curl_4.3         
#> [25] mime_0.10         glue_1.4.2        evaluate_0.14     rmarkdown_2.8    
#> [29] sp_1.4-5          reprex_2.0.0      stringi_1.5.3     compiler_4.0.5

macOS

library(terra)
#> terra version 1.2.10
# remotes::install_github("geocompr/geocompkg")
library(spDataLarge)
nz_elev <- rast(nz_elev)
plot(nz_elev)
# Error in (function (x)  : attempt to apply non-function
# Error in x$.self$finalize() : attempt to apply non-function
# Error in x$.self$finalize() : attempt to apply non-function
# Error in x$.self$finalize() : attempt to apply non-function
# Error in (function (x)  : attempt to apply non-function
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       macOS Big Sur 10.16         
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_GB.UTF-8                 
#>  ctype    en_GB.UTF-8                 
#>  tz       Europe/London               
#>  date     2021-05-19                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  backports     1.2.1   2020-12-09 [1] CRAN (R 4.0.2)
#>  cli           2.5.0   2021-04-26 [1] CRAN (R 4.0.2)
#>  codetools     0.2-16  2018-12-24 [1] CRAN (R 4.0.3)
#>  crayon        1.4.1   2021-02-08 [1] CRAN (R 4.0.2)
#>  curl          4.3.1   2021-04-30 [1] CRAN (R 4.0.2)
#>  digest        0.6.27  2020-10-24 [1] CRAN (R 4.0.2)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.0.2)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.1)
#>  fansi         0.4.2   2021-01-15 [1] CRAN (R 4.0.2)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.2)
#>  htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 4.0.2)
#>  httr          1.4.2   2020-07-20 [1] CRAN (R 4.0.2)
#>  knitr         1.32    2021-04-14 [1] CRAN (R 4.0.3)
#>  lattice       0.20-41 2020-04-02 [1] CRAN (R 4.0.3)
#>  lifecycle     1.0.0   2021-02-15 [1] CRAN (R 4.0.2)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.2)
#>  mime          0.10    2021-02-13 [1] CRAN (R 4.0.3)
#>  pillar        1.6.0   2021-04-13 [1] CRAN (R 4.0.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)
#>  R6            2.5.0   2020-10-28 [1] CRAN (R 4.0.2)
#>  raster        3.4-5   2020-11-14 [1] CRAN (R 4.0.2)
#>  Rcpp          1.0.6   2021-01-15 [1] CRAN (R 4.0.2)
#>  reprex        2.0.0   2021-04-02 [1] CRAN (R 4.0.2)
#>  rlang         0.4.11  2021-04-30 [1] CRAN (R 4.0.2)
#>  rmarkdown     2.7     2021-02-19 [1] CRAN (R 4.0.2)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
#>  sp            1.4-5   2021-01-10 [1] CRAN (R 4.0.2)
#>  spDataLarge * 0.5.1   2021-05-17 [1] local         
#>  stringi       1.6.1   2021-05-10 [1] CRAN (R 4.0.2)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.2)
#>  styler        1.4.1   2021-03-30 [1] CRAN (R 4.0.2)
#>  terra       * 1.2-10  2021-05-13 [1] CRAN (R 4.0.2)
#>  tibble        3.1.1   2021-04-18 [1] CRAN (R 4.0.2)
#>  utf8          1.2.1   2021-03-12 [1] CRAN (R 4.0.2)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.0.2)
#>  withr         2.4.2   2021-04-18 [1] CRAN (R 4.0.2)
#>  xfun          0.22    2021-03-11 [1] CRAN (R 4.0.2)
#>  xml2          1.3.2   2020-04-23 [1] CRAN (R 4.0.2)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.2)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

Ubuntu

library(terra)
#> terra version 1.2.10
# remotes::install_github("geocompr/geocompkg")
library(spDataLarge)
nz_elev <- rast(nz_elev)
plot(nz_elev)
# Error in (function (x)  : attempt to apply non-function
# Error in x$.self$finalize() : attempt to apply non-function
# Error in x$.self$finalize() : attempt to apply non-function
# Error in x$.self$finalize() : attempt to apply non-function
# Error in (function (x)  : attempt to apply non-function
sessionInfo()
#> R version 3.6.3 (2020-02-29)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.1 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] spDataLarge_0.5.1 terra_1.2-10     
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.6        rstudioapi_0.13   xml2_1.3.2        knitr_1.33       
#>  [5] raster_3.4-10     magrittr_2.0.1    lattice_0.20-44   R6_2.5.0         
#>  [9] rlang_0.4.11      stringr_1.4.0     highr_0.9         httr_1.4.2       
#> [13] tools_3.6.3       grid_3.6.3        xfun_0.23         cli_2.5.0        
#> [17] withr_2.4.2       htmltools_0.5.1.1 yaml_2.2.1        digest_0.6.27    
#> [21] fs_1.5.0          codetools_0.2-16  curl_4.3.1        mime_0.10        
#> [25] glue_1.4.2        evaluate_0.14     rmarkdown_2.8     sp_1.4-5         
#> [29] reprex_2.0.0      stringi_1.6.2     compiler_3.6.3

charliejhadley avatar May 19 '21 15:05 charliejhadley

Thank you. Linking this to #30.

rhijmans avatar May 19 '21 18:05 rhijmans

I tried to reproduce it on Windows 8.1 (8 GB) and Linux (64 GB) but it works fine for me. From my observations, this error is very random and executing the same code doesn't always return this error.

Probably the posted code can be simplified to the following form to not download 60 dependent packages:

library("terra")
download.file("https://github.com/Nowosad/spDataLarge/raw/master/data/nz_elev.rda",
              "nz_elev.rda", mode = "wb")
load("nz_elev.rda")
nz_elev = rast(nz_elev)
plot(nz_elev)
#> Error in x$.self$finalize() : attempt to apply non-function
#> Error in x$.self$finalize() : attempt to apply non-function
#> Error in x$.self$finalize() : attempt to apply non-function
#> Error in (function (x)  : attempt to apply non-function
#> Error in (function (x)  : attempt to apply non-function
#> Error in x$.self$finalize() : attempt to apply non-function
#> Error in (function (x)  : attempt to apply non-function

Edit: Reproduced after PC reboot.

kadyb avatar May 19 '21 19:05 kadyb

I get the messages the first time I run this, in a new R session (no need to reboot the computer, for me). Here with a further refined approach.

library("terra")
library("raster")
#terra version 1.2.13
fnz <- "nz_elev.rda"
if (!file.exists(fnz)) {
 download.file("https://github.com/Nowosad/spDataLarge/raw/master/data/nz_elev.rda", fnz, mode = "wb")
}
load("nz_elev.rda")
nz <- rast(nz_elev)
plot(nz)
#Error in (function (x)  : attempt to apply non-function
#Error in x$.self$finalize() : attempt to apply non-function
#Error in x$.self$finalize() : attempt to apply non-function
#Error in x$.self$finalize() : attempt to apply non-function
#Error in (function (x)  : attempt to apply non-function

rhijmans avatar May 19 '21 19:05 rhijmans

It may be worth sending out the minimal example to the Rcpp developers listserv. Perhaps someone on there may be able to provide some insight into why this occurs.

ailich avatar Jan 05 '22 19:01 ailich

It appears that this case has now been fixed; and hopefully most, if not all, other cases as well. Please open a new issue if you find another case of these messages with terra >= 1.6-20

rhijmans avatar Sep 18 '22 00:09 rhijmans