xmc811/mapchina

在Code_Province level上union数据会导致R crash

glidis opened this issue · 2 comments

以下是我的sessionInfo:

R version 4.0.2 (2020-06-22)
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               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] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5         class_7.3-17       crayon_1.3.4       sf_0.9-6          
 [5] dplyr_1.0.2        grid_4.0.2         R6_2.4.1           lifecycle_0.2.0   
 [9] DBI_1.1.0          magrittr_1.5       e1071_1.7-4        units_0.6-7       
[13] pillar_1.4.6       KernSmooth_2.23-17 rlang_0.4.7        rstudioapi_0.11   
[17] ellipsis_0.3.1     vctrs_0.3.2        generics_0.0.2     tools_4.0.2       
[21] glue_1.4.1         purrr_0.3.4        compiler_4.0.2     pkgconfig_2.0.3   
[25] classInt_0.4-3     tidyselect_1.1.0   tibble_3.0.3

我用的是data.table来处理数据,code如下

library(mapchina)
library(data.table)
library(ggplot2)
library(sf)
dt_china <- as.data.table(china)
dt_prov <- dt_china[, list(geometry = st_union(geometry)), by=.(Code_Province)]

但是在Code_Prefecture level上面做union没问题(我怀疑_Code_Perfecture_是个typo,地区的英文为_Prefecture_)

dt_pref <- dt_china[, list(geometry = st_union(geometry)), by=.(Code_Perfecture)]
setnames(dt_pref, 'Code_Perfecture', 'Code_Prefecture')

我试了如下的code,没有发现问题。dt_provdt_pref分别是34x2和347x2的data.frame。运行的时间大概几秒钟。

library(mapchina)
library(data.table)
library(ggplot2)
library(sf)
dt_china <- as.data.table(china)
dt_prov <- dt_china[, list(geometry = st_union(geometry)), by=.(Code_Province)]
dt_pref <- dt_china[, list(geometry = st_union(geometry)), by=.(Code_Perfecture)]

我在attach了package之后的session info如下,不知道我们data.table的版本是否一样呢?

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/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] sf_0.9-6          ggplot2_3.3.2     data.table_1.13.0 mapchina_0.1.0   

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5         rstudioapi_0.11    magrittr_1.5       units_0.6-7        munsell_0.5.0      tidyselect_1.1.0   colorspace_1.4-1  
 [8] R6_2.4.1           rlang_0.4.7        dplyr_1.0.2        tools_4.0.2        grid_4.0.2         gtable_0.3.0       KernSmooth_2.23-17
[15] e1071_1.7-3        DBI_1.1.0          withr_2.3.0        ellipsis_0.3.1     class_7.3-17       tibble_3.0.3       lifecycle_0.2.0   
[22] crayon_1.3.4       purrr_0.3.4        vctrs_0.3.4        glue_1.4.2         compiler_4.0.2     pillar_1.4.6       scales_1.1.1      
[29] generics_0.0.2     classInt_0.4-3     pkgconfig_2.0.3   

Prefecture 拼写错误的问题谢谢指出。在 96cf246 解决。以后会加入正式版本。
此commit在dev branch。可以参考readme里面dev branch版本的安装方法。