ITADN

R crashes when writing custom class

#80Closedbilldenney 创建于 2025-03-30
B
billdenneycommented
I have a reprex for an R crash on Windows 11 with writexl version 1.5.2. When writing a custom `vctrs` record-style object to an excel file, it crashes when used in combination with a character string column but it does not crash when written on its own. You may need to have the `vctrs` library installed to reproduce this. The first example does not crash R, but it writes an xlsx file that does not have a value for the single row of data in the data.frame. The second example crashes R. My guess is that the first example not creating anything for column "B" is a hint that perhaps some representation of the cell is created which does not create a result and then it is indexed into but nothing results. (In other words, column "A" and "B" have different numbers of rows when trying to write, and `writexl` is indexing beyond the last value in "B".) ``` r d_minimal <- structure( list( B = structure( list( number = NA_real_, text = "foo" ), class = c("vctrs_rcrd", "vctrs_vctr") ) ), row.names = c(NA, -1L), class = c("tbl_df", "tbl", "data.frame") ) writexl::write_xlsx(d_minimal, path = "minimal.xlsx") ``` <sup>Created on 2025-03-30 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup> ``` d_minimal2 <- structure( list( A = "foo", B = structure( list( number = NA_real_, text = "foo" ), class = c("vctrs_rcrd", "vctrs_vctr") ) ), row.names = c(NA, -1L), class = c("tbl_df", "tbl", "data.frame") ) writexl::write_xlsx(d_minimal2, path = "minimal2.xlsx") ```
关闭于 2025-04-05 5 条评论