Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataframe with POSIXlt data type leads to Error: C stack usage 7954712 is too close to the limit #1092

Closed
3 tasks done
deepakg opened this issue Oct 16, 2023 · 4 comments
Closed
3 tasks done
Assignees

Comments

@deepakg
Copy link

deepakg commented Oct 16, 2023

Hi Team,

I noticed that the following code goes into infinite recursion:

x = data.frame(a=ymd_hms("2023-01-01 00:00:00"))
x = x %>% mutate(b = trunc(a, "months")) 
str(x)
x %>% datatable()
'data.frame':	1 obs. of  2 variables:
 $ a: POSIXct, format: "2023-01-01"
 $ b: POSIXlt, format: "2023-01-01"
Error: C stack usage  7954712 is too close to the limit

Running traceback() gives:

.....snip....
16: lapply(options, shouldEval)
15: FUN(X[[i]], ...)
14: lapply(options, shouldEval)
13: shouldEval(list)
12: unlist(shouldEval(list))
11: which(unlist(shouldEval(list)))
10: names(which(unlist(shouldEval(list)))) %||% list()
9: JSEvals(x)
8: createPayload(x)
7: toJSON(createPayload(x))
6: widget_data(x, x$id)
5: dots_list(...)
4: tagList(html, widget_data(x, x$id), if (!is.null(sizeInfo$runtime)) {
       tags$script(type = "application/htmlwidget-sizing", `data-for` = x$id, 
           toJSON(sizeInfo$runtime))
   })
3: htmlwidgets:::toHTML(x, standalone = TRUE, knitrOptions = knitrOptions)
2: print.htmlwidget(x)
1: (function (x, ...) 
   UseMethod("print"))(x)

The data type that trunc returns is POSIXlt. It seems to me that serializing this datatype to HTML is breaking. When I change my code above to:

x = data.frame(a=ymd_hms("2023-01-01 00:00:00"))
x = x %>% mutate(b = lubridate::as_date(trunc(a, "months")))
str(x)
x %>% datatable()
'data.frame':	1 obs. of  2 variables:
 $ a: POSIXct, format: "2023-01-01"
 $ b: Date, format: "2023-01-01"

It works as expected.

Any idea why the POSIXlt might be tripping datatable up?

Please note this is also affecting the most recent versions of all packages as well, I had to downgrade to see if it was a recent regression:

## R version 4.3.1 (2023-06-16)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Ventura 13.5.2
## 
## 
## Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8
## 
## time zone: Europe/Amsterdam
## tzcode source: internal
## 
## Package version:
##   askpass_1.1         backports_1.4.1     base64enc_0.1.3    
##   bit_4.0.5           bit64_4.0.5         blob_1.2.4         
##   broom_1.0.5         bslib_0.5.1         cachem_1.0.8       
##   callr_3.7.3         cellranger_1.1.0    cli_3.6.1          
##   clipr_0.8.0         colorspace_2.1-0    compiler_4.3.1     
##   conflicted_1.2.0    cpp11_0.4.6         crayon_1.5.2       
##   crosstalk_1.2.0     curl_5.0.2          data.table_1.14.8  
##   DBI_1.1.3           dbplyr_2.3.3        digest_0.6.33      
##   dplyr_1.1.2         DT_0.24             dtplyr_1.3.1       
##   ellipsis_0.3.2      evaluate_0.22       fansi_1.0.4        
##   farver_2.1.1        fastmap_1.1.1       fontawesome_0.5.2  
##   forcats_1.0.0       fs_1.6.3            gargle_1.5.2       
##   generics_0.1.3      ggplot2_3.4.3       glue_1.6.2         
##   googledrive_2.1.1   googlesheets4_1.1.1 graphics_4.3.1     
##   grDevices_4.3.1     grid_4.3.1          gtable_0.3.3       
##   haven_2.5.3         highr_0.10          hms_1.1.3          
##   htmltools_0.5.6.1   htmlwidgets_1.6.1   httr_1.4.7         
##   ids_1.0.1           isoband_0.2.7       jquerylib_0.1.4    
##   jsonlite_1.8.4      knitr_1.44          labeling_0.4.2     
##   later_1.3.1         lattice_0.21.8      lazyeval_0.2.2     
##   lifecycle_1.0.3     lubridate_1.9.2     magrittr_2.0.3     
##   MASS_7.3.60         Matrix_1.5.4.1      memoise_2.0.1      
##   methods_4.3.1       mgcv_1.8.42         mime_0.12          
##   modelr_0.1.11       munsell_0.5.0       nlme_3.1.162       
##   openssl_2.1.0       pillar_1.9.0        pkgconfig_2.0.3    
##   prettyunits_1.1.1   processx_3.8.2      progress_1.2.2     
##   promises_1.2.1      ps_1.7.5            purrr_1.0.2        
##   R6_2.5.1            ragg_1.2.5          rappdirs_0.3.3     
##   RColorBrewer_1.1.3  Rcpp_1.0.11         readr_2.1.4        
##   readxl_1.4.3        rematch_1.0.1       rematch2_2.1.2     
##   reprex_2.0.2        rlang_1.1.1         rmarkdown_2.25     
##   rstudioapi_0.15.0   rvest_1.0.3         sass_0.4.7         
##   scales_1.2.1        selectr_0.4.2       splines_4.3.1      
##   stats_4.3.1         stringi_1.7.12      stringr_1.5.0      
##   sys_3.4.2           systemfonts_1.0.4   textshaping_0.3.6  
##   tibble_3.2.1        tidyr_1.3.0         tidyselect_1.2.0   
##   tidyverse_2.0.0     timechange_0.2.0    tinytex_0.48       
##   tools_4.3.1         tzdb_0.4.0          utf8_1.2.3         
##   utils_4.3.1         uuid_1.1.0          vctrs_0.6.4        
##   viridisLite_0.4.2   vroom_1.6.3         withr_2.5.0        
##   xfun_0.40           xml2_1.3.5          yaml_2.3.7

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('DT'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/DT').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@yihui
Copy link
Member

yihui commented Oct 16, 2023

Thanks for the report! I investigated for a while, and I think the root problem was from https://github.com/ramnathv/htmlwidgets/blob/d31dd2/R/utils.R#L164 This is a minimal reprex:

x = data.frame(a = Sys.time())
x$b = as.POSIXlt(x$a)
htmlwidgets:::shouldEval(x)
Error: C stack usage  7953960 is too close to the limit

I have submitted a fix to htmlwidgets: ramnathv/htmlwidgets#473

@yihui yihui moved this from Backlog to Todo In Progress in R Markdown Team Projects Oct 16, 2023
@yihui
Copy link
Member

yihui commented Oct 18, 2023

This has been fixed in htmlwidgets. You can install its development version via

remotes::install_github('ramnathv/htmlwidgets')

@gadenbuie
Copy link
Member

@yihui has this always been a problem for DT or was there a recent change that surfaced the recursive behavior of htmlwidgets:::shouldEval()?

@yihui
Copy link
Member

yihui commented Nov 27, 2023

I think this has always been a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants