I use R version 4.2.2 on a Windows Server x64. I have a cleaning script that runs without errors (and includes several printouts), but then gives me a few different fatal errors when trying to do a simple printout of a data.table once it's finished running:
In the first case, the view window will open up but will not display the data. After a few minutes, I get a pop-up that says "Fatal error: Unexpected exception: bad allocation". Once I click OK, I get another pop-up that says "R session disconnected: The browser was disconnected from the R session because another browser connected (only one browser at a time may be connected to an RStudio session). You may reconnect using the button below."
I click reconnect and it restarts my session. I run the script all over again and get the same error.
Meanwhile, when I try a simple printout (in the second example), the error I get is
Error: C stack usage 440484109 is too close to the limit
I work on a massive server with 128 GB of memory (task manager says ~40% is being used by all users) so this shouldn't be a problem.
There is someone else using R on a different account on the server, so maybe that's part of the problem? It's odd to me because I use RStudio on other servers, and as long as it's being used on different accounts, there aren't any issues.
Things I have tried:
resetting RStudio's desktop state as suggested here
Reviewing my code and eliminating this iffy regex expression that didn't throw an error but didn't seem to work:
d$var7 <- gsub("\bCA[.*]\b", NA_character_, d$var7)
Here's my session info:
R version 4.2.2 (2022-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows Server x64 (build 14393) Matrix products: default locale:  LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252  LC_MONETARY=English_United States.1252 LC_NUMERIC=C  LC_TIME=English_United States.1252 attached base packages:  stats graphics grDevices utils datasets methods base other attached packages:  stringi_1.7.12 Hmisc_4.8-0 ggplot2_3.4.1 Formula_1.2-5 survival_3.4-0  lattice_0.20-45 haven_2.5.1 data.table_1.14.8 loaded via a namespace (and not attached):  xfun_0.37 splines_4.2.2 colorspace_2.1-0 vctrs_0.5.2  htmltools_0.5.4 base64enc_0.1-3 utf8_1.2.3 rlang_1.0.6  pillar_1.8.1 foreign_0.8-84 glue_1.6.2 withr_2.5.0  RColorBrewer_1.1-3 jpeg_0.1-10 lifecycle_1.0.3 stringr_1.5.0  munsell_0.5.0 gtable_0.3.1 htmlwidgets_1.6.1 latticeExtra_0.6-30  knitr_1.42 forcats_1.0.0 tzdb_0.3.0 fastmap_1.1.1  fansi_1.0.4 htmlTable_2.4.1 Rcpp_1.0.10 readr_2.1.4  scales_1.2.1 backports_1.4.1 checkmate_2.1.0 deldir_1.0-6  interp_1.1-3 gridExtra_2.3
 digest_0.6.31 grid_4.2.2 cli_3.6.0 tools_4.2.2
 magrittr_2.0.3 tibble_3.1.8 cluster_2.1.4 crayon_1.5.2
 pkgconfig_2.0.3 ellipsis_0.3.2 Matrix_1.5-1 rstudioapi_0.14
 R6_2.5.1 rpart_4.1.19 nnet_7.3-18 compiler_4.2.2
I would like to avoid a full reproducible example of my script, if possible, as my data is confidential and has a lot of random entry errors. The script is long-ish and the whole thing would take quite a bit of effort to reproduce.