RStudio crashes when doing lm

I'm attempting to run some code, example from a textbook called "Design and Analysis of Experiments with R". It runs fine using R console or from ESS and Emacs, but in RStudio crashes. Have I got something set incorrectly? I've tried other sections of code and anything that seems to fit a model causes it to crash.

Ubuntu 18.04, RStudio 1.1.456, R 3.5.1. Here is the offending code

Example 3 p. 24
rm(bread)
library(daewr)
mod0 <-lm( height ~ time, data = bread )
summary (mod0)

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff (and I'm not sure where the bread dataset :bread: comes from).

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

Thanks Mara, it is a reproducible example. Sorry for the confusion, the text writer has actually included the "bread" dataset in the package "daewr". So if you install/load daewr you will have it.

J

Hmm, I'm not able to reproduce the crash (I just ran this in RStudio, and then again as a reprex, below)

library(daewr)
mod0 <-lm( height ~ time, data = bread )
summary (mod0)
#> 
#> Call:
#> lm(formula = height ~ time, data = bread)
#> 
#> Residuals:
#>    Min     1Q Median     3Q    Max 
#> -1.812 -1.141  0.000  1.266  2.250 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)   5.4375     0.7655   7.104 5.65e-05 ***
#> time40        2.8125     1.0825   2.598   0.0288 *  
#> time45        2.8750     1.0825   2.656   0.0262 *  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 1.531 on 9 degrees of freedom
#> Multiple R-squared:  0.5056, Adjusted R-squared:  0.3958 
#> F-statistic: 4.602 on 2 and 9 DF,  p-value: 0.042

Created on 2018-10-05 by the reprex package (v0.2.1.9000)

Some additional Information could be useful as well:

Thanks again Mara, I suspect it is something specific to the OS, are you using Ubuntu 18.04? I also get this when I run the code outside RStudio, but get the consistent crash when trying to run it inside RStudio.
J

Right, I understand that. The crash report (see links above) will give more information and allow the IDE devs to help you troubleshoot.

Appreciate your patience, there are no log files, have not been updated and the ones that are there are months old and contain nothing, i.e. 0 bytes. Here is the traceback.txt file, which also doesn't seem to be much help. All suggestions most welcome. I'd really like to use this for teaching purposes.
J

This is what is in the traceback.txt

RStudio Version: 1.1.456

print(sessionInfo())
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] compiler_3.5.1

/usr/local/bin/R
Linux PC01731 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

What happens if you start a new session and run

example("lm")

(This will run the examples for lm(), attached by default, since it's part of the stats package).

Good idea .... same result, it crashes.
Thx

Longshot: If you put lm() in a script file (don't run it) and press ctrl + click, it will take you to the function definition (the source code for the function). Does this look (for lack of a better word) "normal" to you?

Here's the code as it appears for me:

function (formula, data, subset, weights, na.action, method = "qr", 
  model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, 
  contrasts = NULL, offset, ...) 
{
  ret.x <- x
  ret.y <- y
  cl <- match.call()
  mf <- match.call(expand.dots = FALSE)
  m <- match(c("formula", "data", "subset", "weights", "na.action", 
    "offset"), names(mf), 0L)
  mf <- mf[c(1L, m)]
  mf$drop.unused.levels <- TRUE
  mf[[1L]] <- quote(stats::model.frame)
  mf <- eval(mf, parent.frame())
  if (method == "model.frame") 
    return(mf)
  else if (method != "qr") 
    warning(gettextf("method = '%s' is not supported. Using 'qr'", 
      method), domain = NA)
  mt <- attr(mf, "terms")
  y <- model.response(mf, "numeric")
  w <- as.vector(model.weights(mf))
  if (!is.null(w) && !is.numeric(w)) 
    stop("'weights' must be a numeric vector")
  offset <- as.vector(model.offset(mf))
  if (!is.null(offset)) {
    if (length(offset) != NROW(y)) 
      stop(gettextf("number of offsets is %d, should equal %d (number of observations)", 
        length(offset), NROW(y)), domain = NA)
  }
  if (is.empty.model(mt)) {
    x <- NULL
    z <- list(coefficients = if (is.matrix(y)) matrix(, 
      0, 3) else numeric(), residuals = y, fitted.values = 0 * 
      y, weights = w, rank = 0L, df.residual = if (!is.null(w)) sum(w != 
      0) else if (is.matrix(y)) nrow(y) else length(y))
    if (!is.null(offset)) {
      z$fitted.values <- offset
      z$residuals <- y - offset
    }
  }
  else {
    x <- model.matrix(mt, mf, contrasts)
    z <- if (is.null(w)) 
      lm.fit(x, y, offset = offset, singular.ok = singular.ok, 
        ...)
    else lm.wfit(x, y, w, offset = offset, singular.ok = singular.ok, 
      ...)
  }
  class(z) <- c(if (is.matrix(y)) "mlm", "lm")
  z$na.action <- attr(mf, "na.action")
  z$offset <- offset
  z$contrasts <- attr(x, "contrasts")
  z$xlevels <- .getXlevels(mt, mf)
  z$call <- cl
  z$terms <- mt
  if (model) 
    z$model <- mf
  if (ret.x) 
    z$x <- x
  if (ret.y) 
    z$y <- y
  if (!qr) 
    z$qr <- NULL
  z
}

Yes, thanks. From within RStudio, get exactly the same as you show above.

Using RStudio on Ubuntu 18.04 LInux, latest version of R and RStudio but have installed BLAS libraries. Now every time I try to run a lm in RStudio it crashes. Any suggestions how to debug or fix?
J

Does example(lm) work in a plain R session from the console?

Can you also let us know what BLAS library you're trying to use with R / RStudio? The output of sessionInfo() would be helpful as well.

I believe this is a continuation of @jamaas' earlier post here, which has some of the info that might be relevant:

Correct me if I'm wrong, Jim, of course.

Thanks Mara and Kevin, yes it is the same issue, here is the output from sessionInfo()

R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

Matrix products: default
BLAS: /usr/local/lib/R/lib/libRblas.so
LAPACK: /usr/local/lib/R/lib/libRlapack.so

locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics utils datasets grDevices
[6] methods base

loaded via a namespace (and not attached):
[1] compiler_3.5.1 tools_3.5.1

Using RStudio on Ubuntu 18.04 LInux, latest version of R and RStudio but have installed BLAS libraries. Now every time I try to run a lm in RStudio it crashes. Any suggestions how to debug or fix?
J

Hi Mara, Could you advise me how to proceed to try to get a solution to this problem? I've recompiled R, this time without linking it to openblas libraries, thinking that might have been causing the problem, but it still occurs, every time I try to run any lm function in R, within RStudio it crashes. Can I ask someone is it simply a matter of filing a bug report?
Tkx, J

@kevinushey? (I'm not an IDE dev, so Kevin will have a better idea than I do)

I don't have a good idea, so I would start by trying to get more diagnostic information. You can try attaching the gdb debugger to RStudio. After launching RStudio, open a new terminal and run the command:

sudo gdb -p `pidof rsession`

(where pidof rsession is provided by Sys.getpid() in your RStudio session).

This should open a gdb REPL and attach to the rsession process. After gdb successfully attaches, you should be able to enter

continue

to continue execution of RStudio with the debugger attached. Then, try running example(lm). If the error occurs, gdb should hopefully catch it in the terminal -- you can then try running

backtrace

to get the C stack trace, and copy + paste that stack trace for further inspection.

1 Like

Thanks Kevin, I can find the pidof from within RStudio, and it seems to attach to gdb and continue when I hit enter, however then RStudio becomes unresponsive, both commands executed from with the source code file (Cntl Enter) or lines written in the console do not execute, until the debugger is turned off, with quit. And then RStudio crashes again.

Any suggestions? Thx, J