Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

caught segfault error in R

Tags:

r

I am getting a caught segfault error every time I try to run any plotting functions from the ggplot2 package (1.0.0). I have tried this with qplot, geom_dotplot, geom_histogram, etc. Data from the package (e.g. diamonds or economics) work just fine.

I am operating on Mac OS 10.9.4 (the latest version) and on R 3.1.1 (also the latest version). I get the same error with the standard R GUI, RStudio, and when using R from the command line. The command brings up the default graphic device (Quartz for R GUI and command line), but also the terminal error.

library(ggplot2)
qplot(1:10)

gives me the error:

*** caught segfault ***
address 0x18, cause 'memory not mapped'

Traceback:
 1: .Call("plyr_split_indices", PACKAGE = "plyr", group, n)
 2: split_indices(scale_id, n)
 3: scale_apply(layer_data, x_vars, scale_train, SCALE_X, panel$x_scales)
 4: train_position(panel, data, scale_x(), scale_y())
 5: ggplot_build(x)
 6: print.ggplot(list(data = list(), layers = list(<environment>),     scales = <S4 object of class "Scales">, mapping = list(x = 1:3),     theme = list(), coordinates = list(limits = list(x = NULL,         y = NULL)), facet = list(shrink = TRUE), plot_env = <environment>,     labels = list(x = "1:3", y = "count")))
 7: print(list(data = list(), layers = list(<environment>), scales = <S4 object of class "Scales">,     mapping = list(x = 1:3), theme = list(), coordinates = list(        limits = list(x = NULL, y = NULL)), facet = list(shrink = TRUE),     plot_env = <environment>, labels = list(x = "1:3", y = "count")))

Possible actions:

 1: abort (with core dump, if enabled)
 2: normal R exit
 3: exit R without saving workspace
 4: exit R saving workspace

Here is my session info:

R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

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] graphics  grDevices utils     datasets  stats     methods   base     

other attached packages:
[1] ggplot2_1.0.0 marelac_2.1.3 seacarb_3.0   shape_1.4.1   beepr_1.1     birk_1.1     

loaded via a namespace (and not attached):
[1] audio_0.1-5      colorspace_1.2-4 digest_0.6.4     grid_3.1.1       gtable_0.1.2    
[6] MASS_7.3-34      munsell_0.4.2    plyr_1.8.1       proto_0.3-10     Rcpp_0.11.2     
[11] reshape2_1.4     scales_0.2.4     stringr_0.6.2    tools_3.1.1

I've gathered from others that this is a memory issue of some sort, but this error occurs even when I have over 2 GB of free RAM. I know this is a widely used package, so of course this doesn't happen for everyone, but why is it happening for me? Does anyone know what I can do to fix this problem?

like image 880
CephBirk Avatar asked Sep 04 '14 18:09

CephBirk


3 Answers

In case anyone else has this problem or similar in the future, I sent a bug report to the package maintainer and he recommended uninstalling all installed packages and starting over. I took his advice and it worked!

I followed advice from this posting: http://r.789695.n4.nabble.com/Reset-R-s-library-to-base-packages-only-remove-all-installed-contributed-packages-td3596151.html

ip <- installed.packages()
pkgs.to.remove <- ip[!(ip[,"Priority"] %in% c("base", "recommended")), 1]
sapply(pkgs.to.remove, remove.packages)
like image 112
CephBirk Avatar answered Nov 13 '22 06:11

CephBirk


This is not an answer to this question but it might be helpful for someone. (Inspired by user1310503. Thanks!)

I am working on a data.frame df with three cols: col1, col2, col3. Initially,

df =data.frame(col1=character(),col2=numeric(),col3=numeric(),stringsAsFactors = F)

In the process, rbind is used for many times, like:

aList<-list(col1="aaa", col2 = "123", col3 = "234")
dfNew <- as.data.frame(aList)
df <- rbind(df, dfNew)

At last, df is written to file via data.table::fwrite

data.table::fwrite(x = df, file = fileDF, append = FALSE, row.names = F, quote = F, showProgress = T)

df has 5973 rows and 3 cols. The "caught segfault" always occurs:

address 0x1, cause 'memory not mapped'. 

The solution to this problem is:

aList<-list(col1=as.character("aaa"), col2 = as.numeric("123"), col3 = as.numeric("234"))
dfNew <- as.data.frame(aList)
dfNew$col1 <- as.characer(dfNew$col1)
dfNew$col2 <- as.numeric(dfNew$col2)
dfNew$col3 <- as.numeric(dfNew$col3)
df <- rbind(df, dfNew)

Then this problem is solved. Possible reason is that the classes of cols are different.

like image 28
Huanfa Chen Avatar answered Nov 13 '22 06:11

Huanfa Chen


This is not an answer to this question but it might be useful for someone. I had segfaults when I did pdf to create a PDF graphics device and then used plot. This happened with R 2.15.3, 3.2.4, and one or two other versions, running on Scientific Linux release 6.7. I tried many different things, but the only ways I could get it to work were (a) using png or tiff instead of pdf, or (b) saving large .RData files and then using a completely separate R program to create the graphics.

like image 1
user1310503 Avatar answered Nov 13 '22 05:11

user1310503