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
Segmentation fault involving code using write.xlsx
(and tidyr
)
#267
Comments
Hi @bersbersbers , does |
Usually not, no. But the same example without
Good question. Yes (with 3309cb9).
Have you tried reproducing it? I can on two completely unrelated systems. If you could, you might be able to check more easily which parts of
Yes - segmentation faults and/or "recursive gc invocation". May look like this:
|
Well it's crashing in |
Maybe use |
I'm not sure it's that easy. I saw similar code crash with
True. Check Maybe once more: I am not saying this is |
Also check the second Details block in tidyverse/ggplot2#4635 (comment). This is |
Hm, the only reason I see, why it could crash and how we might be related is due to some options. You could check this if running in an entire clean environment an one with our options set. Something like The thing with the tidyverse interaction is that it's nearly impossible to debug whatever is going on. You begin with one package and a few hours later you're at some minor dependency of a minor dependency that is used is some of their examples (that's not entirely exaggerated). I'll look into it later, but not gonna promise anything. |
Good idea, I'll try that next week.
I noticed the same thing ;) that's one reason why I converted the public API call to the private one. simplifyPieces is already implented in C++: https://github.com/tidyverse/tidyr/blob/master/R/cpp11.R |
@bersbersbers, can you try to use the reprex package and include your session information? I ran the below and didn't have any errors. Note that I changed two things: redirected xlsx creation to a x <- data.frame()
invisible(gctorture2(500))
fun1 <- function() {
as.data.frame(tidyr:::simplifyPieces(
list(c("A", "A"), c("A", "B"), c("B", "A"), c("B", "B")), 2, FALSE
)$strings)
}
fun2 <- function() {
openxlsx::write.xlsx(as.data.frame(1), tempfile(), overwrite = TRUE)
}
y <- fun1()
fun2()
for (i in 1:2) {
print(fun1())
}
#> c..A....A....B....B.. c..A....B....A....B..
#> 1 A A
#> 2 A B
#> 3 B A
#> 4 B B
#> c..A....A....B....B.. c..A....B....A....B..
#> 1 A A
#> 2 A B
#> 3 B A
#> 4 B B Created on 2021-10-08 by the reprex package (v2.0.1) Session infosessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#> setting value
#> version R version 4.1.0 (2021-05-18)
#> os Windows 10 x64
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate English_United States.1252
#> ctype English_United States.1252
#> tz America/New_York
#> date 2021-10-08
#>
#> - Packages -------------------------------------------------------------------
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.0)
#> backports 1.2.1 2020-12-09 [1] CRAN (R 4.1.0)
#> cli 3.0.1 2021-07-17 [1] CRAN (R 4.1.0)
#> crayon 1.4.1 2021-02-08 [1] CRAN (R 4.1.0)
#> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.0)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.1.0)
#> dplyr 1.0.7 2021-06-18 [1] CRAN (R 4.1.0)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.0)
#> fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.0)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.0)
#> generics 0.1.0 2020-10-31 [1] CRAN (R 4.1.0)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.0)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.1.0)
#> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1)
#> knitr 1.34 2021-09-09 [1] CRAN (R 4.1.1)
#> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.1.0)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0)
#> openxlsx 4.2.4.9000 2021-09-28 [1] Github (ycphs/openxlsx@fe7bd5b)
#> pillar 1.6.2 2021-07-29 [1] CRAN (R 4.1.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.0)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0)
#> Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.1.0)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0)
#> rlang 0.4.11 2021-04-30 [1] CRAN (R 4.1.0)
#> rmarkdown 2.10 2021-08-06 [1] CRAN (R 4.1.0)
#> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.1.0)
#> stringi 1.7.4 2021-08-25 [1] CRAN (R 4.1.1)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0)
#> styler 1.5.1 2021-07-13 [1] CRAN (R 4.1.0)
#> tibble 3.1.4 2021-08-25 [1] CRAN (R 4.1.1)
#> tidyr 1.1.3 2021-03-03 [1] CRAN (R 4.1.0)
#> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.1.0)
#> xfun 0.25 2021-08-06 [1] CRAN (R 4.1.0)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.0)
#> zip 2.2.0 2021-05-31 [1] CRAN (R 4.1.0)
#>
#> [1] C:/Users/jmbar/Documents/R/win-library/4.1
#> [2] C:/Program Files/R/R-4.1.0/library Additionally, the error you provided (below) is showing a traceback from
Using the non-exported functions for examples is actually less helpful because there could be some additional steps around them that you didn't account for. Can you make a more simple reprex using exported functions? |
I tried it at home and I could confirm the crash (R 4.1.1 on Arch). After a rebuild of |
x <- data.frame()
invisible(gctorture2(500))
fun1 <- function() {
as.data.frame(tidyr:::simplifyPieces(
list(c("A", "A"), c("A", "B"), c("B", "A"), c("B", "B")), 2, FALSE
)$strings)
}
fun2 <- function() {
openxlsx::write.xlsx(as.data.frame(1), tempfile(), overwrite = TRUE)
}
y <- fun1()
fun2()
for (i in 1:2) {
print(fun1())
}
#> c..A....A....B....B.. c..A....B....A....B..
#> 1 A A
#> 2 A B
#> 3 B A
#> 4 B B
#> c..A....A....B....B.. c..A....B....A....B..
#> 1 A A
#> 2 A B
#> 3 B A
#> 4 B B Created on 2021-10-08 by the reprex package (v2.0.1)
That code still fails for me when pasted into R (not as a reprex, though), Output on Windows:
You may be misunderstanding (or maybe I am). tidyverse/ggplot2#4635 (comment) does not use any non-exported functions: df <- data.frame(A.A = 0, A.B = 0, B.A = 0, B.B = 0)
invisible(gctorture2(500))
invisible(data.table::as.data.table(1))
x <- tidyr::build_longer_spec(
df, tidyr::everything(), names_to = c("C", "D"), names_sep = "\\."
)
openxlsx::write.xlsx(as.data.frame(1), "tmp.xlsx", overwrite = TRUE)
print(tidyr::build_longer_spec(
df, tidyr::everything(), names_to = c("C", "D"), names_sep = "\\."
))
print(tidyr::build_longer_spec(
df, tidyr::everything(), names_to = c("C", "D"), names_sep = "\\."
)) |
Great, so I'm not crazy after all ;)
What do you mean by "rebuild"? I reinstalled all packages two nights ago using
Still possible of course, but as I said, I reinstalled everything...
Can you give an example of another call that produces the same error? That would be super helpful in the other issue, and might give Thanks for your help so far! |
And you are only starting from 10 lines of code. Imagine having to isolate such a case from thousands of lines of code, with the problem first appeared in a |
With build I meant Well my time is spent voluntarily ... 😄 Since you're on windows it might be something else pending. I'll see if I can revive my windows R install, but most likely it won't be soon I'm afraid. Maybe end of next week. And for me it was random too. Wrapping For the other libs, I just replaced the code with other packages of mine (readspss and readstata13). The latter caused issues since it's installation was most likely to old. Once I rebuild it, the problem went away. |
Thanks for your investigations!
I see! I tried I have noticed that changing system-wide things, or restarting after a while (such as after a weekend), makes the problem seem to have gone away. But usually, this just means you have to repro it once using a smaller Adding I haven't been able to find a x <- data.frame()
invisible(gctorture2(50))
fun1 <- function() {
as.data.frame(tidyr:::simplifyPieces(
list(c("A", "A"), c("A", "B"), c("B", "A"), c("B", "B")), 2, FALSE
)$strings)
}
fun2 <- function() {
openxlsx::write.xlsx(as.data.frame(1), tempfile()) # repros
# readstata13::save.dta13(as.data.frame(1), tempfile()) # does not repro
# readspss::read.sav(system.file("extdata", "electric.sav", package = "readspss")) # does not repro
}
y <- fun1() # try(fun1) does not repro!
fun2()
while (TRUE) {
print(fun1())
} |
Fyi, I can now repro this consistently for every version of |
Fyi, apparently fixed in r-lib/cpp11#245. |
Thanks for the heads-up! |
I am cross-posting this here and in tidyverse/tidyr#1163 after a series of earlier investigations (thomasp85/patchwork#278, rstudio/rmarkdown#2229, tidyverse/ggplot2#4635).
I am seeing reproducible segmentation faults on Linux and Windows using the following code. There are two packages remaining which are involved,
tidyr
andopenxlsx
. I have excluded many packages along the way, but I am unable to get any further with regard to these two:The text was updated successfully, but these errors were encountered: