jtextor / dagitty

Graphical analysis of structural causal models / graphical causal models.
GNU General Public License v2.0
282 stars 46 forks source link

R crash due to dagitty error: libicu data files missing? #24

Closed johnfrombluff closed 4 years ago

johnfrombluff commented 5 years ago

Firstly, thank you very much for this great software and web service!

I'm trying to run it on Fedora 30, and get a crash with the error:

Failed to create ICU collator, are ICU data files missing?

I see this error occurs on the package build check on CRAN also.

Stacktrace:

library(dagitty) RAA <- dagitty( "pdag { I -> B; {A SN PBC} -> I; A <-> {PBC SN} }" )

#

Fatal error in , line 0

Failed to create ICU collator, are ICU data files missing?

# # #

FailureMessage Object: 0x7ffeada1b650

==== C stack trace ===============================

/lib64/libnode.so.64(v8::base::debug::StackTrace::StackTrace()+0x1a) [0x7fe44c55e88a]
/lib64/libnode.so.64(+0x92ccd1) [0x7fe44bae6cd1]
/lib64/libnode.so.64(V8_Fatal(char const*, int, char const*, ...)+0x177) [0x7fe44c55a387]
/lib64/libnode.so.64(v8::internal::Collator::InitializeCollator(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::JSObject>)+0x473) [0x7fe44c23b843]
/lib64/libnode.so.64(v8::internal::Runtime_CreateCollator(int, v8::internal::Object**, v8::internal::Isolate*)+0x192) [0x7fe44c3608d2]
[0x2cc02a7dc0d8]

caught illegal operation address 0x7fe44b92538d, cause 'illegal operand'

Traceback: 1: context_eval(join(src), private$context) 2: get_str_output(context_eval(join(src), private$context)) 3: ct$eval(paste("global.", name, "=", value)) 4: .jsassign(xv, .jsp("GraphParser.parseGuess(global.", xv, ").toString()")) 5: doTryCatch(return(expr), name, parentenv, handler) 6: tryCatchOne(expr, names, parentenv, handlers[[1L]]) 7: tryCatchList(expr, classes, parentenv, handlers) 8: tryCatch({ .jsassign(xv, as.character(x)) .jsassign(xv, .jsp("GraphParser.parseGuess(global.", xv, ").toString()")) r <- structure(.jsget(xv), class = "dagitty")}, error = function(e) { stop(e)}, finally = { .deleteJSVar(xv)}) 9: dagitty("pdag { I -> B; {A SN PBC} -> I; A <-> {PBC SN} }")

jtextor commented 5 years ago

Dear John, thank you very much for your message. I can confirm that there is a problem in Fedora, I managed to reproduce it in a VirtualBox VM on my Mac. Unfortunately, the problem seems to be in the V8 package, a dependency of dagitty. It crashes when executing the underlying JavaScript code generated by dagitty. It should not be possible for the V8 package to crash when executing JavaScript code. I will contact the maintainer of that package, @jeroen with a minimal example and see whether he's willing to investigate this. If not, I'll try to find a workaround.

Best regards Johannes

johnfrombluff commented 5 years ago

Dear Johannes,

Thank you very much indeed for your quick and helpful reply. I really appreciate your help, and your amazing package.

Best wishes,

John

jeroen commented 5 years ago

This might be an issue with the libv8 that ships with Fedora. We saw this before on MacOS, there is even a special mention of this in the V8 source code. Tracking the problem here: https://github.com/jeroen/V8/issues/65

Some questions: why does dagitty need ICU? Are you doing string operations on characters?

Could you maybe check if the same problem occurs when you run the same js code in nodejs on the same Fedora version? R and Node share the same V8 engine, so if we can reproduce the problem in nodejs, that makes it easier to explain to the Fedora people.

jtextor commented 5 years ago

Hi all, and sorry this took me so long. I was on vacation the past couple of weeks.

I think I have isolated the problem. I am comparing two strings using the "localeCompare" method. This seems to require loading ICU, which then causes a segfault. Minimal example:

V8::new_context()$eval("\"a\".localeCompare(\"b\")")

I could fix this problem of course by working around the localeCompare method somehow but would it be worth fixing it in V8 itself?

jeroen commented 5 years ago

Yes I would like to fix this, but the problem is not in the R bindings but in the system provided libv8 and libicu. But this example may make it easier to isolate the problem upstream in Fedora.

jeroen commented 5 years ago

It looks like this might not be fixed in Fedora until they upgrade to icu 64 in Fedora 32. So if you can work around it by avoiding localeCompare() in your code I would highly recommend that.

jtextor commented 4 years ago

It seems that this will not be fixed so soon in Fedora. I therefore changed the dagitty code so that it no longer uses localeCompare. It should now work again on Fedora as per the latest commit. Closing this for the moment.

jeroen commented 4 years ago

Thanks. For reference, you can track the Fedora issue here: https://bugzilla.redhat.com/show_bug.cgi?id=1755114

dmvianna commented 3 years ago

I'm experiencing the same under NixOS 20.03. Is this fixed in the current dagitty master?

dibatti5 commented 1 year ago

Hi, I'm having the exact same error '$ operator is invalid for atomic vectors and have tried uninstalling and reinstalling dagitty, R and RStudio to no avail. Has this been fixed?