yihui / animation

A gallery of animations in statistics and utilities to create animations
https://yihui.org/animation/
206 stars 60 forks source link

Error address (nil), cause 'memory not mapped' #126

Open nmolanog opened 4 years ago

nmolanog commented 4 years ago

this error was presented while runing this code:

library(animation)
library(tidyverse)

mu_seq<-c(seq(0,15,by = .5),seq(15,0,by = -.5),seq(0,-15,by = -.5),rev(seq(0,-15,by = -.5)))
sig_seq<-c(rev(seq(0.001,225,length.out = 20)),seq(0.001,225,length.out = 15))
dfp<-data.frame(mu=c(mu_seq,
                     rep(0,length(sig_seq))),
                sig=c(rep(225,length(mu_seq)),sig_seq))

saveGIF({
  ani.options(interval = 0.2, nmax = nrow(dfp))
  ## use a loop to create images one by one
  for (i in 1:ani.options('nmax')) {
    m1<-dfp[i,1]
    sd1<-sqrt(dfp[i,2])
    weight_lim<-c(-40, 40)
    pdnorm1<-ggplot(data = data.frame(weight = weight_lim), aes(weight)) +
      stat_function(fun = dnorm, n = 101, args = list(mean = m1, sd = sd1),aes(color="black")) +
      ylab(expression(paste("f(x|",mu,",",sigma^2,")"))) +xlab("x") +  
      scale_color_identity(name = "",
                           breaks = c("black", "red", "blue","green"),
                           labels = c(substitute(paste(mu,"= ",m1,", ",sigma^2,"= ",sd1),list(m1=round(m1,1),sd1=round(sd1,3)))),
                           guide = "legend")+
      ylim(0,.25)+
      theme_bw()
    print(pdnorm1)
    ani.pause()   ## pause for a while ('interval')
  }
}, interval = 0.05, movie.name = 'dnorm.gif', ani.width = 680, ani.height = 500)

The Error output is this

Traceback:
 1: magick_image_write(image, format, quality, depth, density, comment)
 2: magick::image_write(anim, path = output)
 3: magick.convert(files = files, output = output, loop = loop, interval = interval,     dispose = dispose)
 4: im.convert(img.files, output = path.expand(movie.name), convert = convert,     cmd.fun = cmd.fun, clean = clean, extra.opts = extra.opts)
 5: saveGIF({    ani.options(interval = 0.2, nmax = nrow(dfp))    for (i in 1:ani.options("nmax")) {        m1 <- dfp[i, 1]        sd1 <- sqrt(dfp[i, 2])        weight_lim <- c(-40, 40)        pdnorm1 <- ggplot(data = data.frame(weight = weight_lim),             aes(weight)) + stat_function(fun = dnorm, n = 101,             args = list(mean = m1, sd = sd1), aes(color = "black")) +             ylab(expression(paste("f(x|", mu, ",", sigma^2, ")"))) +             xlab("x") + scale_color_identity(name = "", breaks = c("black",             "red", "blue", "green"), labels = c(substitute(paste(mu,             "= ", m1, ", ", sigma^2, "= ", sd1), list(m1 = round(m1,             1), sd1 = round(sd1, 3)))), guide = "legend") + ylim(0,             0.25) + theme_bw()        print(pdnorm1)        ani.pause()    }}, interval = 0.05, movie.name = "dnorm.gif", ani.width = 680,     ani.height = 500)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

my session info

─ Session info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.2 (2020-06-22)
 os       Ubuntu 18.04.4 LTS          
 system   x86_64, linux-gnu           
 ui       X11                         
 language en                          
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/Bogota              
 date     2020-07-27                  

─ Packages ───────────────────────────────────────────────────────────────────
 package     * version date       lib source        
 animation   * 2.6     2018-12-11 [1] CRAN (R 4.0.2)
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)
 backports     1.1.8   2020-06-17 [1] CRAN (R 4.0.2)
 blob          1.2.1   2020-01-20 [1] CRAN (R 4.0.2)
 broom         0.7.0   2020-07-09 [1] CRAN (R 4.0.2)
 callr         3.4.3   2020-03-28 [1] CRAN (R 4.0.2)
 cellranger    1.1.0   2016-07-27 [1] CRAN (R 4.0.2)
 cli           2.0.2   2020-02-28 [1] CRAN (R 4.0.2)
 colorspace    1.4-1   2019-03-18 [1] CRAN (R 4.0.2)
 crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.2)
 DBI           1.1.0   2019-12-15 [1] CRAN (R 4.0.2)
 dbplyr        1.4.4   2020-05-27 [1] CRAN (R 4.0.2)
 desc          1.2.0   2018-05-01 [1] CRAN (R 4.0.2)
 devtools      2.3.0   2020-04-10 [1] CRAN (R 4.0.2)
 digest        0.6.25  2020-02-23 [1] CRAN (R 4.0.2)
 dplyr       * 1.0.0   2020-05-29 [1] CRAN (R 4.0.2)
 ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.2)
 fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.2)
 forcats     * 0.5.0   2020-03-01 [1] CRAN (R 4.0.2)
 fs            1.4.2   2020-06-30 [1] CRAN (R 4.0.2)
 generics      0.0.2   2018-11-29 [1] CRAN (R 4.0.2)
 ggplot2     * 3.3.2   2020-06-19 [1] CRAN (R 4.0.2)
 glue          1.4.1   2020-05-13 [1] CRAN (R 4.0.2)
 gtable        0.3.0   2019-03-25 [1] CRAN (R 4.0.2)
 haven         2.3.1   2020-06-01 [1] CRAN (R 4.0.2)
 hms           0.5.3   2020-01-08 [1] CRAN (R 4.0.2)
 httr          1.4.2   2020-07-20 [1] CRAN (R 4.0.2)
 jsonlite      1.7.0   2020-06-25 [1] CRAN (R 4.0.2)
 lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.2)
 lubridate     1.7.9   2020-06-08 [1] CRAN (R 4.0.2)
 magrittr      1.5     2014-11-22 [1] CRAN (R 4.0.2)
 memoise       1.1.0   2017-04-21 [1] CRAN (R 4.0.2)
 modelr        0.1.8   2020-05-19 [1] CRAN (R 4.0.2)
 munsell       0.5.0   2018-06-12 [1] CRAN (R 4.0.2)
 pillar        1.4.6   2020-07-10 [1] CRAN (R 4.0.2)
 pkgbuild      1.1.0   2020-07-13 [1] CRAN (R 4.0.2)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)
 pkgload       1.1.0   2020-05-29 [1] CRAN (R 4.0.2)
 prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.2)
 processx      3.4.3   2020-07-05 [1] CRAN (R 4.0.2)
 ps            1.3.3   2020-05-08 [1] CRAN (R 4.0.2)
 purrr       * 0.3.4   2020-04-17 [1] CRAN (R 4.0.2)
 R6            2.4.1   2019-11-12 [1] CRAN (R 4.0.2)
 Rcpp          1.0.5   2020-07-06 [1] CRAN (R 4.0.2)
 readr       * 1.3.1   2018-12-21 [1] CRAN (R 4.0.2)
 readxl        1.3.1   2019-03-13 [1] CRAN (R 4.0.2)
 remotes       2.1.1   2020-02-15 [1] CRAN (R 4.0.2)
 reprex        0.3.0   2019-05-16 [1] CRAN (R 4.0.2)
 rlang         0.4.7   2020-07-09 [1] CRAN (R 4.0.2)
 rprojroot     1.3-2   2018-01-03 [1] CRAN (R 4.0.2)
 rstudioapi    0.11    2020-02-07 [1] CRAN (R 4.0.2)
 rvest         0.3.5   2019-11-08 [1] CRAN (R 4.0.2)
 scales        1.1.1   2020-05-11 [1] CRAN (R 4.0.2)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
 stringi       1.4.6   2020-02-17 [1] CRAN (R 4.0.2)
 stringr     * 1.4.0   2019-02-10 [1] CRAN (R 4.0.2)
 testthat      2.3.2   2020-03-02 [1] CRAN (R 4.0.2)
 tibble      * 3.0.3   2020-07-10 [1] CRAN (R 4.0.2)
 tidyr       * 1.1.0   2020-05-20 [1] CRAN (R 4.0.2)
 tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.2)
 tidyverse   * 1.3.0   2019-11-21 [1] CRAN (R 4.0.2)
 usethis       1.6.1   2020-04-29 [1] CRAN (R 4.0.2)
 vctrs         0.3.2   2020-07-15 [1] CRAN (R 4.0.2)
 withr         2.2.0   2020-04-20 [1] CRAN (R 4.0.2)

The error is not present if number of iterations is reduced

rm(list=ls())
library(animation)
library(tidyverse)

mu_seq<-c(seq(0,15,by = 1.5),seq(15,0,by = -1.5),seq(0,-15,by = -1.5),rev(seq(0,-15,by = -1.5)))
sig_seq<-c(rev(seq(0.001,225,length.out = 20)),seq(0.001,225,length.out = 15))
dfp<-data.frame(mu=c(mu_seq,
                     rep(0,length(sig_seq))),
                sig=c(rep(225,length(mu_seq)),sig_seq))

saveGIF({
  ani.options(interval = 0.2, nmax = nrow(dfp))
  ## use a loop to create images one by one
  for (i in 1:ani.options('nmax')) {
    m1<-dfp[i,1]
    sd1<-sqrt(dfp[i,2])
    weight_lim<-c(-40, 40)
    pdnorm1<-ggplot(data = data.frame(weight = weight_lim), aes(weight)) +
      stat_function(fun = dnorm, n = 101, args = list(mean = m1, sd = sd1),aes(color="black")) +
      ylab(expression(paste("f(x|",mu,",",sigma^2,")"))) +xlab("x") +  
      scale_color_identity(name = "",
                           breaks = c("black", "red", "blue","green"),
                           labels = c(substitute(paste(mu,"= ",m1,", ",sigma^2,"= ",sd1),list(m1=round(m1,3),sd1=round(sd1,3)))),
                           guide = "legend")+
      ylim(0,.125)+
      theme_bw()
    print(pdnorm1)
    ani.pause()   ## pause for a while ('interval')
  }
}, interval = 0.05, movie.name = 'dnorm.gif', ani.width = 680, ani.height = 500)
#> Output at: dnorm.gif
#> [1] TRUE

Created on 2020-07-27 by the reprex package (v0.3.0)

yulijia commented 4 years ago

I couldn't reproduce the bug, both scripts are running well on my CentOS server.

Maybe the memory of your machine is too limited to run the first script.

Here is my session info.

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.3.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
 [1] splines   parallel  stats4    stats     graphics  grDevices utils     datasets 
 [9] methods   base     

other attached packages:
 [1] animation_2.6               scClassify_1.0.0            monocle_2.16.0             
 [4] DDRTree_0.1.5               irlba_2.3.3                 VGAM_1.1-3                 
 [7] Matrix_1.2-18               plyr_1.8.6                  ggpubr_0.4.0               
[10] viridis_0.5.1               viridisLite_0.3.0           MAST_1.14.0                
[13] ggplot2_3.3.2               cluster_2.1.0               Rtsne_0.15                 
[16] mclust_5.4.6                edgeR_3.30.3                limma_3.44.3               
[19] dplyr_1.0.0                 SingleCellExperiment_1.10.1 SummarizedExperiment_1.18.2
[22] DelayedArray_0.14.1         matrixStats_0.56.0          Biobase_2.48.0             
[25] GenomicRanges_1.40.0        GenomeInfoDb_1.24.2         IRanges_2.22.2             
[28] S4Vectors_0.26.1            BiocGenerics_0.34.0        

loaded via a namespace (and not attached):
 [1] colorspace_1.4-1       ggsignif_0.6.0         ellipsis_0.3.1        
 [4] rio_0.5.16             XVector_0.28.0         proxy_0.4-24          
 [7] rstudioapi_0.11        farver_2.0.3           graphlayouts_0.7.0    
[10] ggrepel_0.8.2          docopt_0.7.1           polyclip_1.10-0       
[13] hopach_2.48.0          broom_0.7.0            kernlab_0.9-29        
[16] pheatmap_1.0.12        ggforce_0.3.2          compiler_4.0.2        
[19] backports_1.1.8        tweenr_1.0.1           tools_4.0.2           
[22] igraph_1.2.5           gtable_0.3.0           glue_1.4.1            
[25] GenomeInfoDbData_1.2.3 RANN_2.6.1             reshape2_1.4.4        
[28] Rcpp_1.0.5             carData_3.0-4          slam_0.1-47           
[31] cellranger_1.1.0       vctrs_0.3.2            nlme_3.1-148          
[34] ggraph_2.0.3           stringr_1.4.0          openxlsx_4.1.5        
[37] lifecycle_0.2.0        statmod_1.4.34         rstatix_0.6.0         
[40] zlibbioc_1.34.0        MASS_7.3-51.6          scales_1.1.1          
[43] tidygraph_1.2.0        hms_0.5.3              RColorBrewer_1.1-2    
[46] curl_4.3               gridExtra_2.3          segmented_1.2-0       
[49] fastICA_1.2-2          stringi_1.4.6          densityClust_0.3      
[52] zip_2.0.4              BiocParallel_1.22.0    rlang_0.4.7           
[55] pkgconfig_2.0.3        bitops_1.0-6           qlcMatrix_0.9.7       
[58] lattice_0.20-41        purrr_0.3.4            labeling_0.3          
[61] tidyselect_1.1.0       magrittr_1.5           R6_2.4.1              
[64] magick_2.4.0           generics_0.0.2         combinat_0.0-8        
[67] pillar_1.4.6           haven_2.3.1            foreign_0.8-80        
[70] withr_2.2.0            mgcv_1.8-31            proxyC_0.1.5          
[73] mixtools_1.2.0         survival_3.2-3         abind_1.4-5           
[76] RCurl_1.98-1.2         tibble_3.0.3           crayon_1.3.4          
[79] car_3.0-8              locfit_1.5-9.4         grid_4.0.2            
[82] readxl_1.3.1           minpack.lm_1.2-1       data.table_1.12.8     
[85] FNN_1.1.3              forcats_0.5.0          HSMMSingleCell_1.8.0  
[88] sparsesvd_0.2          digest_0.6.25          tidyr_1.1.0           
[91] RcppParallel_5.0.2     munsell_0.5.0