strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science
https://strengejacke.github.io/sjPlot
609 stars 93 forks source link

tab_model() saved file will disapear, when other code is executed after? #650

Open b-niu opened 4 years ago

b-niu commented 4 years ago

Hi, I have met this strange bug like below:

Let's make a directory named "test":

dir.create("test")

rm(model); gc()

There is nothing in this path:

# nothing in this dir:
list.files(path = "test")

character(0)

head(ToothGrowth)

len supp dose 1 4.2 VC 0.5 2 11.5 VC 0.5 3 7.3 VC 0.5 4 5.8 VC 0.5 5 6.4 VC 0.5 6 10.0 VC 0.5

We can create a html file named "test1.html" like this:

foo <- function() {
+   model <- lm(len ~ dose, data = ToothGrowth)
+   sjPlot::tab_model(model, file = "test/test1.html")
+ }

foo()

list.files(path = "test")

[1] "test1.html"

But when we save a pdf file generated by other functons, the html file will disapear!

bar <- function() {
  model <- lm(len ~ dose, data = ToothGrowth)
  sjPlot::tab_model(model, file = "test/test2.html")
  p1 <- forestmodel::forest_model(model)
  ggplot2::ggsave(filename = "test/test2.pdf", plot = p1)
}
bar()

Resized limits to included dashed line in forest panel Saving 7.91 x 5.71 in image

list.files(path = "test")
**# No html file saved!**

[1] "test1.html" "test2.pdf"

It seems that, the file "test2.html" will be saved, and soon removed by some reason.

The session info are:

R version 4.0.1 (2020-06-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936    LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C                               LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] ggpubr_0.3.0     avocado_0.1.0    ngsrtools_0.2.13 readxl_1.3.1     forcats_0.5.0    stringr_1.4.0    dplyr_1.0.0      purrr_0.3.4     
 [9] readr_1.3.1      tidyr_1.1.0      tibble_3.0.1     ggplot2_3.3.1    tidyverse_1.3.0 

loaded via a namespace (and not attached):
  [1] TH.data_1.0-10     minqa_1.2.4        colorspace_1.4-1   ggsignif_0.6.0     ellipsis_0.3.1     class_7.3-17       rio_0.5.16        
  [8] sjlabelled_1.1.5   estimability_1.3   parameters_0.8.0   fs_1.4.1           rstudioapi_0.11    farver_2.0.3       fansi_0.4.1       
 [15] mvtnorm_1.1-1      lubridate_1.7.9    xml2_1.3.2         codetools_0.2-16   splines_4.0.1      knitr_1.28         DMwR_0.4.1        
 [22] maftools_2.4.05    sjmisc_2.8.5       jsonlite_1.6.1     nloptr_1.2.2.1     ggeffects_0.15.0   broom_0.5.6        dbplyr_1.4.4      
 [29] effectsize_0.3.1   compiler_4.0.1     httr_1.4.1         sjstats_0.18.0     emmeans_1.4.7      backports_1.1.7    assertthat_0.2.1  
 [36] Matrix_1.2-18      lazyeval_0.2.2     cli_2.0.2          htmltools_0.4.0    tools_4.0.1        gtable_0.3.0       glue_1.4.1        
 [43] Rcpp_1.0.4.6       carData_3.0-4      cellranger_1.1.0   vctrs_0.3.1        sjPlot_2.8.4       nlme_3.1-148       lmtest_0.9-37     
 [50] insight_0.8.5      xfun_0.14          openxlsx_4.1.5     forestmodel_0.5.0  lme4_1.1-23        rvest_0.3.5        lifecycle_0.2.0   
 [57] statmod_1.4.34     rstatix_0.5.0      MASS_7.3-51.6      zoo_1.8-8          scales_1.1.1       hms_0.5.3          sandwich_2.5-1    
 [64] RColorBrewer_1.1-2 yaml_2.2.1         quantmod_0.4.17    curl_4.3           rpart_4.1-15       stringi_1.4.6      bayestestR_0.7.0  
 [71] TTR_0.23-6         boot_1.3-25        zip_2.0.4          rlang_0.4.6        pkgconfig_2.0.3    lattice_0.20-41    ROCR_1.0-11       
 [78] htmlwidgets_1.5.1  labeling_0.3       tidyselect_1.1.0   magrittr_1.5       R6_2.4.1           generics_0.0.2     multcomp_1.4-13   
 [85] DBI_1.1.0          pillar_1.4.4       haven_2.3.1        foreign_0.8-80     withr_2.2.0        mgcv_1.8-31        xts_0.12-0        
 [92] survival_3.1-12    abind_1.4-5        performance_0.4.7  modelr_0.1.8       crayon_1.3.4       car_3.0-8          grid_4.0.1        
 [99] data.table_1.12.8  blob_1.2.1         vcd_1.4-7          reprex_0.3.0       digest_0.6.25      xtable_1.8-4       munsell_0.5.0     
gorkang commented 3 years ago

Not sure if this can be related to: https://github.com/ropensci/targets/issues/285

strengejacke commented 3 years ago

It might be related to the fact that the code is run inside a for-loop, but that's just a guess.