sgaure / lfe

Source code repository for the R package lfe on CRAN.
53 stars 18 forks source link

Segfault when using `demeanlist` #18

Open mattblackwell opened 5 years ago

mattblackwell commented 5 years ago

Thanks for writing lfe, it's really great! One issue that I've found is that the function demeanlist() appears to be fairly sensitive to the way that the factors are specified, which can lead to a segfault. Here is a MWE:

library(lfe)
mm <- matrix(1:10, nrow = 20, ncol = 3)
ff <- rep(1:4, each = 5)

## works
out <- demeanlist(mtx = mm, fl = list(factor(ff)))

## segfault
out <- demeanlist(mtx = mm, fl = list(ff))

## segfault
out <- demeanlist(mtx = mm, fl = factor(ff))

Either of the latter two calls leads to the follow:

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

Traceback:
 1: .Call(C_demeanlist, mtx = mm, fl = .fl, icpt = 0L, eps = getOption("lfe.eps"),     threads = getOption("lfe.threads"), progress = getOption("lfe.pint"),     accel = getOption("lfe.accel"), means = FALSE, weights = NULL,     scale = TRUE, attrs = NULL)
 2: eval(as.call(c(list(quote(.Call), quote(C_demeanlist)), ff)),     env)
 3: eval(as.call(c(list(quote(.Call), quote(C_demeanlist)), ff)),     env)
 4: demeanlist(mtx = mm, fl = list(ff))

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

It might be worthwhile to add checks for the fl argument so that demeanlist exits more gracefully under these conditions.

sgaure commented 5 years ago

Whoops,

thanks, I'll have a look at it.

On Fri, Jun 21, 2019 at 4:27 PM +0200, "Matthew Blackwell" notifications@github.com wrote:

Thanks for writing lfe, it's really great! One issue that I've found is that the function demeanlist() appears to be fairly sensitive to the way that the factors are specified, which can lead to a segfault. Here is a MWE: library(lfe) mm <- matrix(1:10, nrow = 20, ncol = 3) ff <- rep(1:4, each = 5)

works

out <- demeanlist(mtx = mm, fl = list(factor(ff)))

segfault

out <- demeanlist(mtx = mm, fl = list(ff))

segfault

out <- demeanlist(mtx = mm, fl = factor(ff))

Either of the latter two calls leads to the follow: caught segfault address 0x0, cause 'memory not mapped'

Traceback: 1: .Call(C_demeanlist, mtx = mm, fl = .fl, icpt = 0L, eps = getOption("lfe.eps"), threads = getOption("lfe.threads"), progress = getOption("lfe.pint"), accel = getOption("lfe.accel"), means = FALSE, weights = NULL, scale = TRUE, attrs = NULL) 2: eval(as.call(c(list(quote(.Call), quote(C_demeanlist)), ff)), env) 3: eval(as.call(c(list(quote(.Call), quote(C_demeanlist)), ff)), env) 4: demeanlist(mtx = mm, fl = list(ff))

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

It might be worthwhile to add checks for the fl argument so that demeanlist exits more gracefully under these conditions.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.