Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to crash R?

Tags:

r

crash

Is there a simple way to trigger a crash in R? This is for testing purposes only, to see how a certain program that uses R in the background reacts to a crash and help determine if some rare problems are due to crashes or not.

like image 705
Szabolcs Avatar asked Aug 05 '14 12:08

Szabolcs


3 Answers

The easiest way is to call C-code. C provides a standard function abort()[1] that does what you want. You need to call: .Call("abort").

As @Phillip pointed out you may need to load libc via:

  • on Linux, dyn.load("/lib/x86_64-linux-gnu/libc.so.6") before issuing .Call("abort"). The path may of course vary depending on your system.

  • on OS X, dyn.load("/usr/lib/libc.dylib")

  • on Windows (I just tested it on XP as I could not get hold of a newer version.) you will need to install Rtools[2]. After that you should load dyn.load("C:/.../Rtools/bin/cygwin1.dll").

like image 68
lord.garbage Avatar answered Oct 16 '22 11:10

lord.garbage


There is an entire package on GitHub dedicated to this:

crash

R package that purposely crash an R session. WARNING: intended for test.

How to install a package from github is covered in other questions.

like image 36
Dirk Eddelbuettel Avatar answered Oct 16 '22 10:10

Dirk Eddelbuettel


I'm going to steal an idea from @Spacedman, but I'm giving him full conceptual credit by copying from his Twitter feed:

Segfault #rstats in one easy step: options(device=function(){});plot(1) reported Danger, will crash your R session. — Barry Rowlingson (@geospacedman) July 16, 2014

like image 17
Thomas Avatar answered Oct 16 '22 11:10

Thomas