braverock / PerformanceAnalytics

211 stars 105 forks source link

chart.Correlation generates warning message "In par(usr) : argument 1 does not name a graphical parameter" #179

Closed peter-bastian closed 9 months ago

peter-bastian commented 2 years ago

Description

chart.Correlation() is throwing the warning "In par(usr) : argument 1 does not name a graphical parameter". Digging into this a bit, it is happening in the panel.cor function, second call to text(). Going further, the warning is generated in the par() function when the text() function reaches the end and invisible() is called. The "..." argument to the par() function is converted to args variable. It contains the following:

Browse[3]> list(...)
[[1]]
[1] 2707.40 8987.60   11.04   36.96

Expected behavior

No warnings to be generated

Minimal, reproducible example

Using the csv file attached to this issue report...

data <- as.data.frame(read.csv('PA_Warning.csv'))
PerformanceAnalytics::chart.Correlation(data, histogram = TRUE, pch = 19, cex.main = 0.75)

This will generate 28 warnings:

There were 28 warnings (use warnings() to see them)
> warnings()
Warning messages:
1: In par(usr) : argument 1 does not name a graphical parameter

Session Info

R version 4.2.0 (2022-04-22)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.5.1

Matrix products: default
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] LinMod_2.1.0

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.0             splines_4.2.0              foreach_1.5.2             
 [4] carData_3.0-5              prodlim_2019.11.13         datawizard_0.4.1          
 [7] stats4_4.2.0               cellranger_1.1.0           bayestestR_0.12.1         
[10] robustbase_0.95-0          ggrepel_0.9.1              globals_0.15.0            
[13] ipred_0.9-13               pillar_1.7.0               lattice_0.20-45           
[16] glue_1.6.2                 quadprog_1.5-8             pROC_1.18.0               
[19] digest_0.6.29              hardhat_1.2.0              colorspace_2.0-3          
[22] recipes_1.0.1              Matrix_1.4-1               plyr_1.8.7                
[25] timeDate_4021.104          pkgconfig_2.0.3            listenv_0.8.0             
[28] caret_6.0-92               purrr_0.3.4                patchwork_1.1.1           
[31] scales_1.2.0               gower_1.0.0                lava_1.6.10               
[34] tibble_3.1.7               mgcv_1.8-40                farver_2.1.0              
[37] generics_0.1.2             car_3.1-0                  ggplot2_3.3.6             
[40] ellipsis_0.3.2             withr_2.5.0                nnet_7.3-17               
[43] cli_3.3.0                  survival_3.3-1             magrittr_2.0.3            
[46] crayon_1.5.1               readxl_1.4.0               future_1.26.1             
[49] fansi_1.0.3                parallelly_1.32.0          nlme_3.1-157              
[52] MASS_7.3-56                xts_0.12.1                 class_7.3-20              
[55] tools_4.2.0                data.table_1.14.2          lifecycle_1.0.1           
[58] see_0.7.1                  stringr_1.4.0              munsell_0.5.0             
[61] qqplotr_0.0.5              compiler_4.2.0             rlang_1.0.4               
[64] grid_4.2.0                 iterators_1.0.14           rstudioapi_0.13           
[67] PerformanceAnalytics_2.0.4 labeling_0.4.2             gtable_0.3.0              
[70] ModelMetrics_1.2.2.2       codetools_0.2-18           abind_1.4-5               
[73] reshape2_1.4.4             R6_2.5.1                   gridExtra_2.3             
[76] zoo_1.8-10                 lubridate_1.8.0            dplyr_1.0.9               
[79] performance_0.9.1          future.apply_1.9.0         utf8_1.2.2                
[82] insight_0.17.1             stringi_1.7.6              parallel_4.2.0            
[85] Rcpp_1.0.8.3               vctrs_0.4.1                rpart_4.1.16              
[88] DEoptimR_1.0-11            tidyselect_1.1.2          

PA_Warning.csv

GillesSanMartin commented 1 year ago

I'm not a user of this package, but I stumbled upon this bug report while searching for the same warning message that appeared in one of my old functions.

I fixed it with a simple code change in the panel function used within the pairs() function, and I suspect it might be the same problem here.

Old code with warning(s)

usr <- par("usr") 
par(usr)

New code without warning :

usr <- par("usr") 
par(usr=usr)
joshuaulrich commented 9 months ago

Thanks for the patch @GillesSanMartin!