Skip to content

Instantly share code, notes, and snippets.

@infotroph
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infotroph/0a621f5c74d3d6085427 to your computer and use it in GitHub Desktop.
Save infotroph/0a621f5c74d3d6085427 to your computer and use it in GitHub Desktop.
Intermittent segfaults when geom_histogram has >128 groups
library(ggplot2)
set.seed(12345678)
sessionInfo()
# Loading required package: methods
# R version 3.2.0 Patched (2015-05-13 r68364)
# Platform: x86_64-apple-darwin10.8.0 (64-bit)
# Running under: OS X 10.8.5 (Mountain Lion)
# 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] methods stats graphics grDevices utils datasets base
# other attached packages:
# [1] ggplot2_1.0.1
# loaded via a namespace (and not attached):
# [1] MASS_7.3-40 colorspace_1.2-6 scales_0.2.4 magrittr_1.5
# [5] plyr_1.8.2 tools_3.2.0 gtable_0.1.2 reshape2_1.4.1
# [9] Rcpp_0.11.6 stringi_0.4-1 grid_3.2.0 stringr_1.0.0
# [13] digest_0.6.8 proto_0.3-10 munsell_0.4.2
littledata = data.frame(x=1:128, y=rlnorm(128))
bigdata = data.frame(x=1:129, y=rlnorm(129))
# plots as expected
lp = ggplot(littledata, aes(x, y))+geom_histogram(stat="identity", binwidth=1)
for (i in 1:20){
print(i)
try(plot(lp+ggtitle(paste("128 points", i))))
}
# always warns "position_stack requires constant width",
# intermittently throws error, hangs, or segfaults.
# See below for details.
bp = ggplot(bigdata, aes(x, y))+geom_histogram(stat="identity", binwidth=1)
for(i in 1:20){
print(i)
try(plot(bp+ggtitle(paste("129 points", i))))
}
## End demo code
## As noted above, the same plotting code produces different error messages
## depending on RNG state. I show here output from three runs on my machine:
## with set.seed(12345678) as above:
# zsh> Rscript --vanilla histfailure.r
# Loading required package: methods
# R version 3.2.0 Patched (2015-05-13 r68364)
# Platform: x86_64-apple-darwin10.8.0 (64-bit)
# Running under: OS X 10.8.5 (Mountain Lion)
# 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] methods stats graphics grDevices utils datasets base
# other attached packages:
# [1] ggplot2_1.0.1
# loaded via a namespace (and not attached):
# [1] MASS_7.3-40 colorspace_1.2-6 scales_0.2.4 magrittr_1.5
# [5] plyr_1.8.2 tools_3.2.0 gtable_0.1.2 reshape2_1.4.1
# [9] Rcpp_0.11.6 stringi_0.4-1 grid_3.2.0 stringr_1.0.0
# [13] digest_0.6.8 proto_0.3-10 munsell_0.4.2
# [1] 1
# [1] 2
# [1] 3
# [1] 4
# [1] 5
# [1] 6
# [1] 7
# [1] 8
# [1] 9
# [1] 10
# [1] 11
# [1] 12
# [1] 13
# [1] 14
# [1] 15
# [1] 16
# [1] 17
# [1] 18
# [1] 19
# [1] 20
# [1] 1
# [1] 2
# [1] 3
# [1] 4
# [1] 5
# [1] 6
# [1] 7
# [1] 8
# [1] 9
# [1] 10
# [1] 11
# [1] 12
# [1] 13
# [1] 14
# Error : Results must be all atomic, or all data frames
# In addition: There were 14 warnings (use warnings() to see them)
# [1] 15
# [1] 16
# [1] 17
# Error : arguments imply differing number of rows: 136, 129
# In addition: Warning messages:
# 1: In loop_apply(n, do.ply) :
# position_stack requires constant width: output may be incorrect
# 2: In loop_apply(n, do.ply) :
# position_stack requires constant width: output may be incorrect
# 3: In loop_apply(n, do.ply) :
# position_stack requires constant width: output may be incorrect
# [1] 18
# [1] 19
# [1] 20
# Warning messages:
# 1: In loop_apply(n, do.ply) :
# position_stack requires constant width: output may be incorrect
# 2: In loop_apply(n, do.ply) :
# position_stack requires constant width: output may be incorrect
# 3: In loop_apply(n, do.ply) :
# position_stack requires constant width: output may be incorrect
# zsh>
## with set.seed(12):
# zsh> Rscript --vanilla histfailure.r
# Loading required package: methods
# R version 3.2.0 Patched (2015-05-13 r68364)
# Platform: x86_64-apple-darwin10.8.0 (64-bit)
# Running under: OS X 10.8.5 (Mountain Lion)
# 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] methods stats graphics grDevices utils datasets base
# other attached packages:
# [1] ggplot2_1.0.1
# loaded via a namespace (and not attached):
# [1] MASS_7.3-40 colorspace_1.2-6 scales_0.2.4 magrittr_1.5
# [5] plyr_1.8.2 tools_3.2.0 gtable_0.1.2 reshape2_1.4.1
# [9] Rcpp_0.11.6 stringi_0.4-1 grid_3.2.0 stringr_1.0.0
# [13] digest_0.6.8 proto_0.3-10 munsell_0.4.2
# [1] 1
# [1] 2
# [1] 3
# [1] 4
# [1] 5
# [1] 6
# [1] 7
# [1] 8
# [1] 9
# [1] 10
# [1] 11
# [1] 12
# [1] 13
# [1] 14
# [1] 15
# [1] 16
# [1] 17
# [1] 18
# [1] 19
# [1] 20
# [1] 1
# [1] 2
# [1] 3
# [1] 4
# [1] 5
# [1] 6
# [1] 7
# [1] 8
# [1] 9
# [1] 10
# [1] 11
# [1] 12
# [1] 13
# *** caught segfault ***
# address 0x0, cause 'unknown'
# Traceback:
# 1: dim(x)
# 2: FUN(X[[i]], ...)
# 3: lapply(res, NROW)
# 4: unlist(lapply(res, NROW))
# 5: list_to_dataframe(res, attr(.data, "split_labels"), .id, id_as_factor)
# 6: ldply(.data = pieces, .fun = .fun, ..., .progress = .progress, .inform = .inform, .parallel = .parallel, .paropts = .paropts)
# 7: ddply(data, "xmin", strategy, width = width)
# 8: collide(data, .$width, .$my_name(), pos_stack)
# 9: get(x, envir = this, inherits = inh)(this, ...)
# 10: .$position$adjust(data)
# 11: .fun(piece, ...)
# 12: (function (i) { piece <- pieces[[i]] if (.inform) { res <- try(.fun(piece, ...)) if (inherits(res, "try-error")) { piece <- paste(capture.output(print(piece)), collapse = "\n") stop("with piece ", i, ": \n", piece, call. = FALSE) } } else { res <- .fun(piece, ...) } progress$step() res})(1L)
# 13: eval(substitute(expr), envir, enclos)
# 14: evalq((function (i) { piece <- pieces[[i]] if (.inform) { res <- try(.fun(piece, ...)) if (inherits(res, "try-error")) { piece <- paste(capture.output(print(piece)), collapse = "\n") stop("with piece ", i, ": \n", piece, call. = FALSE) } } else { res <- .fun(piece, ...) } progress$step() res})(1L), <environment>)
# 15: doTryCatch(return(expr), name, parentenv, handler)
# 16: tryCatchOne(expr, names, parentenv, handlers[[1L]])
# 17: tryCatchList(expr, classes, parentenv, handlers)
# 18: tryCatch(evalq((function (i) { piece <- pieces[[i]] if (.inform) { res <- try(.fun(piece, ...)) if (inherits(res, "try-error")) { piece <- paste(capture.output(print(piece)), collapse = "\n") stop("with piece ", i, ": \n", piece, call. = FALSE) } } else { res <- .fun(piece, ...) } progress$step() res})(1L), <environment>), error = .rcpp_error_recorder)
# 19: withCallingHandlers(tryCatch(evalq((function (i) { piece <- pieces[[i]] if (.inform) { res <- try(.fun(piece, ...)) if (inherits(res, "try-error")) { piece <- paste(capture.output(print(piece)), collapse = "\n") stop("with piece ", i, ": \n", piece, call. = FALSE) } } else { res <- .fun(piece, ...) } progress$step() res})(1L), <environment>), error = .rcpp_error_recorder), warning = .rcpp_warning_recorder)
# aborting ...
# zsh: segmentation fault Rscript --vanilla histfailure.r
# zsh>
## With set.seed(3000):
# zsh> Rscript --vanilla histfailure.r
# Loading required package: methods
# R version 3.2.0 Patched (2015-05-13 r68364)
# Platform: x86_64-apple-darwin10.8.0 (64-bit)
# Running under: OS X 10.8.5 (Mountain Lion)
# 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] methods stats graphics grDevices utils datasets base
# other attached packages:
# [1] ggplot2_1.0.1
# loaded via a namespace (and not attached):
# [1] MASS_7.3-40 colorspace_1.2-6 scales_0.2.4 magrittr_1.5
# [5] plyr_1.8.2 tools_3.2.0 gtable_0.1.2 reshape2_1.4.1
# [9] Rcpp_0.11.6 stringi_0.4-1 grid_3.2.0 stringr_1.0.0
# [13] digest_0.6.8 proto_0.3-10 munsell_0.4.2
# [1] 1
# [1] 2
# [1] 3
# [1] 4
# [1] 5
# [1] 6
# [1] 7
# [1] 8
# [1] 9
# [1] 10
# [1] 11
# [1] 12
# [1] 13
# [1] 14
# [1] 15
# [1] 16
# [1] 17
# [1] 18
# [1] 19
# [1] 20
# [1] 1
# <R hangs here until I kill the process>
@infotroph
Copy link
Author

The warnings are probably related to this previously-reported geom_bar issue, but I'm not claiming (yet) that the errors come from the same place.

@infotroph
Copy link
Author

On inspection, this isn't specific to geom_histogram: Switching to geom_bar produces the same behavior, though it does (predictably) change the pattern of which plots give which errors from a given seed value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment