ShanaScogin / BayesPostEst

An R package to generate and plot postestimation quantities after estimating Bayesian regression models using MCMC
https://shanascogin.github.io/BayesPostEst/
GNU General Public License v3.0
12 stars 2 forks source link

mcmcReg shows warning when providing file extension in call #52

Closed jkarreth closed 5 years ago

jkarreth commented 5 years ago

This might be intended behavior, but just in case @jayrobwilliams you want to take a look (sorry for the pseudo-code, but hopefully this is clear):

> mcmcReg(TTfm.mcmod, 
+         coefnames = c("Intercept", ...),
+         file = "Tables/tab_tt.tex")
Warning message:
In for (n in impnames) if (!is.null(genImp <- impenv[[n]])) { :
  closing unused connection 3 (../Tables/tab_tt.tex.tex)

> mcmcReg(TTfm.mcmod, 
+         coefnames = c("Intercept", ..."),
+         file = "Tables/tab_tt")
> 

Both calls print the correct table, the first as tab_tt.tex.tex, the second as tab_tt.tex..

jkarreth commented 5 years ago

Aha! The warning does not show up when also providing format = "tex" as intended. So I think I can close this right away.

jayrobwilliams commented 5 years ago

Does the first function call still produce a file called tab_tt.tex.tex when you set format = "tex"? If so, I can add a quick regex to check if .tex is part of the supplied filename or not.

jkarreth commented 5 years ago

Here is what I get now:

library("BayesPostEst")
m <- MCMCpack::MCMClogit(Y ~ X1 + X2, data = sim_data)

mcmcReg(m, file = "table1.tex")
# produces `table1.tex.tex`

mcmcReg(m, file = "table1")
# produces `table1.tex`

mcmcReg(m, format = "tex", file = "table1.tex")
# produces no output

mcmcReg(m, format = "tex", file = "table1")
# produces no output

Session info:

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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] BayesPostEst_0.1.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2         pillar_1.4.2       compiler_3.6.1     RColorBrewer_1.1-2 plyr_1.8.4         runjags_2.0.4-4    tools_3.6.1        bitops_1.0-6       boot_1.3-23       
[10] tibble_2.1.3       gtable_0.3.0       lattice_0.20-38    texreg_1.36.24     pkgconfig_2.0.2    rlang_0.4.0        Matrix_1.2-17      GGally_1.4.0       parallel_3.6.1    
[19] SparseM_1.77       coda_0.19-3        stringr_1.4.0      dplyr_0.8.3        MatrixModels_0.4-1 rjags_4-9          ggmcmc_1.3         gtools_3.8.1       caTools_1.17.1.2  
[28] R2jags_0.5-7       grid_3.6.1         tidyselect_0.2.5   reshape_0.8.8      glue_1.3.1         R6_2.4.0           gdata_2.18.0       reshape2_1.4.3     tidyr_0.8.3       
[37] purrr_0.3.2        ggplot2_3.2.1      ROCR_1.0-7         magrittr_1.5       mcmc_0.9-6         MASS_7.3-51.4      ggridges_0.5.1     gplots_3.0.1.1     scales_1.0.0      
[46] R2WinBUGS_2.1-21   assertthat_0.2.1   abind_1.4-5        colorspace_1.4-1   quantreg_5.42      KernSmooth_2.23-15 stringi_1.4.3      MCMCpack_1.4-4     lazyeval_0.2.2    
[55] munsell_0.5.0      crayon_1.3.4      
jayrobwilliams commented 5 years ago

It was expecting just format = 'latex', so I've added a regex to catch both 'tex' and 'latex'. The file extension duplication is an annoying thing built into texreg, but I added a call to sub() to strip it out. Pushed to develop as 04b3b2240adf2e4a114547a4b0d5d76b7d712a3e.