amices / mice

Multivariate Imputation by Chained Equations
https://amices.org/mice/
GNU General Public License v2.0
427 stars 107 forks source link

Segmentation fault on Apple arm64 for md.pattern() #513

Closed gH2AX closed 1 year ago

gH2AX commented 1 year ago

I load a dataset in the variable 'ww', then when i call md.pattern(ww), my R session crashes with the following error message:

*** caught segfault ***
address 0x0, cause 'invalid permissions'

Traceback:
 1: grDevices::dev.capabilities("semiTransparency")
 2: supports.transparent()
 3: mdc(1)
 4: ifelse(R[nrow(R):1, ], mdc(1), mdc(2))
 5: md.pattern(ww)
gerkovink commented 1 year ago

Can you make a reprex, because I cannot reproduce.

gH2AX commented 1 year ago

It seems reprex has its own issues..

> reprex(md.pattern(iris.mis))
ℹ Rendering reprex...
Error in `reprex_render()`:
! This reprex appears to crash R. Call `reprex()` again with `std_out_err = TRUE` to get more info.
Run `rlang::last_error()` to see where the error occurred.
> reprex(md.pattern(iris.mis), std_out_err = TRUE)
ℹ Rendering reprex...
sh: +RTS: command not found
Error: pandoc document conversion failed with error 127
In addition: Warning message:
In system(command) : error in running command
gerkovink commented 1 year ago

Can you provide some more info on the incomplete data? Perhaps share the data that reproduces the behaviour.

gH2AX commented 1 year ago

It's unspecific, I tried various datasets. But here's one expample:

The iris dataset is a built-in dataset in R. I have the version 4.2.2. I run the following commands:

library(missForest)
library(mice)

iris.mis = prodNA(iris, noNA = 0.1)
iris.mis = subset(iris.mis, select=-c(Species))

md.pattern(iris.mis)

caught segfault

I already re-installed the mice package from tar.gz - makes no difference. Everything else runs very smoothly..

stefvanbuuren commented 1 year ago

Curious. I get various 'sprintf' is deprecated: messages when building the package, but the code works on my machine. Perhaps you upgraded to Ventura and need to re-install tools?

library(missForest)
library(mice)
#> 
#> Attaching package: 'mice'
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following objects are masked from 'package:base':
#> 
#>     cbind, rbind

iris.mis = prodNA(iris, noNA = 0.1)
iris.mis = subset(iris.mis, select=-c(Species))

md.pattern(iris.mis)

#>    Sepal.Width Sepal.Length Petal.Length Petal.Width   
#> 95           1            1            1           1  0
#> 15           1            1            1           0  1
#> 10           1            1            0           1  1
#> 2            1            1            0           0  2
#> 12           1            0            1           1  1
#> 1            1            0            1           0  2
#> 1            1            0            0           1  2
#> 9            0            1            1           1  1
#> 1            0            1            1           0  2
#> 3            0            1            0           1  2
#> 1            0            0            1           1  2
#>             14           15           16          19 64
sessionInfo()
#> R version 4.2.1 (2022-06-23)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS Monterey 12.6
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/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     
#> 
#> other attached packages:
#> [1] mice_3.14.8    missForest_1.5
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.9           pillar_1.8.1         compiler_4.2.1      
#>  [4] highr_0.9            R.methodsS3_1.8.2    R.utils_2.12.1      
#>  [7] iterators_1.0.14     tools_4.2.1          rngtools_1.5.2      
#> [10] digest_0.6.30        lattice_0.20-45      tibble_3.1.8        
#> [13] evaluate_0.18        lifecycle_1.0.3      R.cache_0.16.0      
#> [16] pkgconfig_2.0.3      rlang_1.0.6          doRNG_1.8.2         
#> [19] reprex_2.0.2         foreach_1.5.2        DBI_1.1.3           
#> [22] cli_3.4.1            rstudioapi_0.14      yaml_2.3.6          
#> [25] parallel_4.2.1       xfun_0.34            fastmap_1.1.0       
#> [28] dplyr_1.0.10         withr_2.5.0          styler_1.8.0        
#> [31] stringr_1.4.1        knitr_1.40           generics_0.1.3      
#> [34] vctrs_0.5.0          fs_1.5.2             grid_4.2.1          
#> [37] tidyselect_1.2.0     glue_1.6.2           R6_2.5.1            
#> [40] fansi_1.0.3          rmarkdown_2.17       tidyr_1.2.1         
#> [43] purrr_0.3.5          magrittr_2.0.3       backports_1.4.1     
#> [46] codetools_0.2-18     htmltools_0.5.3      itertools_0.1-3     
#> [49] assertthat_0.2.1     randomForest_4.7-1.1 utf8_1.2.2          
#> [52] stringi_1.7.8        broom_1.0.1          R.oo_1.25.0

Created on 2022-11-09 with reprex v2.0.2

gH2AX commented 1 year ago

Still on Monterey.. what's the issue with tools? And how would I re-install it? It's a base-package and cannot be removed.

gerkovink commented 1 year ago

Can also not reproduce:

library(missForest)
library(mice)
iris.mis = prodNA(iris, noNA = 0.1)
iris.mis = subset(iris.mis, select=-c(Species))
md.pattern(iris.mis, rotate.names = TRUE)

#>    Sepal.Length Sepal.Width Petal.Length Petal.Width   
#> 97            1           1            1           1  0
#> 10            1           1            1           0  1
#> 14            1           1            0           1  1
#> 2             1           1            0           0  2
#> 11            1           0            1           1  1
#> 4             1           0            1           0  2
#> 1             1           0            0           1  2
#> 10            0           1            1           1  1
#> 1             0           0            1           0  3
#>              11          17           17          17 62

sessionInfo()
#> R version 4.2.2 (2022-10-31)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS Monterey 12.6
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/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     
#> 
#> other attached packages:
#> [1] mice_3.14.0    missForest_1.5
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.9           compiler_4.2.2       pillar_1.7.0        
#>  [4] highr_0.9            iterators_1.0.14     tools_4.2.2         
#>  [7] rngtools_1.5.2       digest_0.6.29        lattice_0.20-45     
#> [10] tibble_3.1.7         evaluate_0.15        lifecycle_1.0.1     
#> [13] pkgconfig_2.0.3      rlang_1.0.3          doRNG_1.8.2         
#> [16] reprex_2.0.2         foreach_1.5.2        DBI_1.1.2           
#> [19] cli_3.3.0            rstudioapi_0.13      yaml_2.3.5          
#> [22] parallel_4.2.2       xfun_0.31            fastmap_1.1.0       
#> [25] withr_2.5.0          stringr_1.4.0        dplyr_1.0.9         
#> [28] knitr_1.39           generics_0.1.3       fs_1.5.2            
#> [31] vctrs_0.4.1          grid_4.2.2           tidyselect_1.1.2    
#> [34] glue_1.6.2           R6_2.5.1             fansi_1.0.3         
#> [37] rmarkdown_2.14       tidyr_1.2.0          purrr_0.3.4         
#> [40] magrittr_2.0.3       backports_1.4.1      codetools_0.2-18    
#> [43] htmltools_0.5.2      ellipsis_0.3.2       itertools_0.1-3     
#> [46] assertthat_0.2.1     randomForest_4.7-1.1 utf8_1.2.2          
#> [49] stringi_1.7.6        broom_1.0.0          crayon_1.5.1

Created on 2022-11-09 with reprex v2.0.2

gerkovink commented 1 year ago

Since it seems to be isolated to your R instance, and not to aarch64-apple-darwin20 (64-bit) in general; perhaps a fresh install of the latest R framework would suffice.

@gH2AX You are not by any chance running R through Anaconda?

stefvanbuuren commented 1 year ago

In general, you need the proper compilers if you are installing from source (mice has some C and C++ code). You can get these from CRAN. I remember struggling a bit when switching to Apple's ARM CPU to get up and running.

gH2AX commented 1 year ago

@gH2AX You are not by any chance running R through Anaconda?

No, I am not running Anaconda.

[…] you need the proper compilers if you are installing from source […]

I only tried to compile from source once this error emerged..

gerkovink commented 1 year ago

I have a feeling that a clean install of the most recent R framework and RStudio would fix. Have you tried this?

The error you receive is not related to mice, but stems from grDevices::dev.capabilities("semiTransparency").

stefvanbuuren commented 1 year ago

Yes agree. What happens if you run

z <- grDevices::dev.capabilities("semiTransparency")
class(z)
#> [1] "list"
z
#> $semiTransparency
#> [1] TRUE

Created on 2022-11-11 with reprex v2.0.2

gH2AX commented 1 year ago

Yes agree. What happens if you run

z <- grDevices::dev.capabilities("semiTransparency")
class(z)
#> [1] "list"
z
#> $semiTransparency
#> [1] TRUE

Created on 2022-11-11 with reprex v2.0.2

An empty (white) Quartz window opens. And I get the same output as you. Btw: If I call md.pattern() on a simple two-column numeric data.frame, it works! I will eventually try the clean install.

stefvanbuuren commented 1 year ago

Hmm, interesting. I do not see a Quartz window.

I will close because we cannot reproduce and it's likely to be related to something outside mice. Sorry, we cannot help, but thanks for bringing up the issue.

Feel free to reopen if you think it's mice-related.

gerkovink commented 1 year ago

Reinstalling xquartz may help