Segmentation fault when caching object with mutate containing formula/function #2

Closed
dgrtwo opened this Issue Jan 11, 2017 · 1 comment

Projects

None yet

2 participants

@dgrtwo
dgrtwo commented Jan 11, 2017

I'm running into a segmentation fault when knitr caches a particular kind of object- one in which a column was created with mutate and it contains either a formula or a newly-defined function .

I think, though I'm not sure, that this has to do with the way the environment is carried along with the formula/formula. This occurs only with the development version of dplyr (which uses bindrcpp), not the version in CRAN. (That's why I opened it here rather than on dplyr).

Reproducible example

Here's an example knitr document. If I skip the final chunk it works (meaning the problem only happens when the lapply is in the mutate.

```{r setup, include=FALSE}
knitr::opts_chunk$set(cache = TRUE)
```

```{r}
library(dplyr)
obj <- data_frame(x = 1) %>%
  mutate(f = list(some ~ formula + here))

obj
```

The traceback of the segmentation fault is then:

 *** caught segfault ***
address 0x0, cause 'unknown'

Traceback:
 1: .Call("bindrcpp_callback_symbol", PACKAGE = "bindrcpp", name,     fun, payload)
 2: fun(name, ...)
 3: (function (value) {    if (!missing(value)) {        stop("Binding is read-only.", call. = FALSE)    }    fun(name, ...)})()
 4: envlist(e)
 5: (function (e) {    if (is.environment(e)) {        name <- table$getname(e)        if (is.null(name)) {            name <- table$insert(e)            data <- list(bindings = envlist(e), enclos = parent.env(e),                 attributes = attributes(e), isS4 = isS4(e), locked = environmentIsLocked(e))            key <- lazyLoadDBinsertValue(data, datafile, ascii,                 compress, envhook)            assign(name, key, envir = envenv)        }        name    }})(<environment>)
 6: lazyLoadDBinsertValue(data, datafile, ascii, compress, envhook)
 7: (function (e) {    if (is.environment(e)) {        name <- table$getname(e)        if (is.null(name)) {            name <- table$insert(e)            data <- list(bindings = envlist(e), enclos = parent.env(e),                 attributes = attributes(e), isS4 = isS4(e), locked = environmentIsLocked(e))            key <- lazyLoadDBinsertValue(data, datafile, ascii,                 compress, envhook)            assign(name, key, envir = envenv)        }        name    }})(<environment>)
 8: lazyLoadDBinsertValue(data, datafile, ascii, compress, envhook)
 9: (function (e) {    if (is.environment(e)) {        name <- table$getname(e)        if (is.null(name)) {            name <- table$insert(e)            data <- list(bindings = envlist(e), enclos = parent.env(e),                 attributes = attributes(e), isS4 = isS4(e), locked = environmentIsLocked(e))            key <- lazyLoadDBinsertValue(data, datafile, ascii,                 compress, envhook)            assign(name, key, envir = envenv)        }        name    }})(<environment>)
10: lazyLoadDBinsertVariable(vars[i], from, datafile, ascii, compress,     envhook)
11: getFromNamespace("makeLazyLoadDB", "tools")(knit_global(), path,     variables = keys)
12: cache$save(objects, outname, hash, lazy = options$cache.lazy)
13: block_cache(options, output, objs)
14: block_exec(params)
15: call_block(x)
16: process_group.block(group)
17: process_group(group)
18: withCallingHandlers(if (tangle) process_tangle(group) else process_group(group),     error = function(e) {        setwd(wd)        cat(res, sep = "\n", file = output %n% "")        message("Quitting from lines ", paste(current_lines(i),             collapse = "-"), " (", knit_concord$get("infile"),             ") ")    })
19: process_file(text, output)
20: knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet,     encoding = encoding)
21: rmarkdown::render("/Users/drobinson/Dropbox/test2.Rmd", encoding = "UTF-8")
An irrecoverable exception occurred. R is aborting now ...

This error persists (and gives the same message) if instead of a formula, it is an anonymous function, such as: mutate(f = list(some ~ formula + here)).

The error does not occur with the current version of

Session Info

Results of devtools::session_info():

Session info -------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.0 (2016-05-03)
 system   x86_64, darwin13.4.0        
 ui       RStudio (1.0.44)            
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/New_York            
 date     2017-01-11                  

Packages -----------------------------------------------------------------------------------------------------------------
 package    * version    date       source                       
 assertthat   0.1        2013-12-06 CRAN (R 3.3.0)               
 DBI          0.5-1      2016-09-10 CRAN (R 3.3.0)               
 devtools     1.12.0     2016-06-24 CRAN (R 3.3.0)               
 digest       0.6.11     2017-01-03 cran (@0.6.11)               
 dplyr      * 0.5.0.9000 2017-01-11 Github (hadley/dplyr@165b760)
 evaluate     0.9        2016-04-29 CRAN (R 3.3.0)               
 htmltools    0.3.5      2016-03-21 CRAN (R 3.3.0)               
 knitr        1.14.1     2016-08-18 Github (yihui/knitr@973bdb2) 
 magrittr     1.5        2014-11-22 CRAN (R 3.3.0)               
 memoise      1.0.0      2016-01-29 CRAN (R 3.3.0)               
 R6           2.2.0      2016-10-05 cran (@2.2.0)                
 Rcpp         0.12.8     2016-11-17 cran (@0.12.8)               
 rmarkdown    1.1        2016-10-16 CRAN (R 3.3.0)               
 stringi      1.1.2      2016-10-01 cran (@1.1.2)                
 stringr      1.1.0      2016-08-19 CRAN (R 3.3.0)               
 tibble       1.2        2016-08-26 cran (@1.2)                  
 withr        1.0.2      2016-06-20 cran (@1.0.2)                

@krlmlr
Owner
krlmlr commented Jan 11, 2017

Thanks, confirmed. hadley/dplyr@eef12c8 is the offending commit, but we still need to fix dplyr. (The active environment leaks through the formula and contains bindings that are no longer valid and cause a crash when queried; dplyr needs to clean up the environment by removing the bindings it created.)

@krlmlr krlmlr closed this Jan 11, 2017
@krlmlr krlmlr referenced this issue in hadley/dplyr Jan 11, 2017
Open

Need to clean up active environment #2358

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