johnmchambers / XRJulia

XR-style Interface to Julia (from "Extending R")
33 stars 2 forks source link

Is there any way to stop/clear Julia? #10

Closed woodwards closed 6 years ago

woodwards commented 6 years ago

Is there any way to stop/clear Julia remotely using XRJulia?

Thanks

woodwards commented 6 years ago

I think I am having a problem because an old session of Julia is stuck and I don't know how to reset it.

> library(XRJulia)
> findJulia() # finds Julia
[1] "C:\\Users\\WoodwardS\\AppData\\Local\\JuliaPro-0.6.2.1\\Julia-0.6.2\\bin\\julia.exe"
> findJulia(test=TRUE) # checks that Julia exists
[1] TRUE
> juliaAddToPath(getwd()) # tell Julia to looks for modules here
> juliaUsing("combin")
Error in assign(.actionMetaName(anames[[i]]), actions[[i]], envir = where) : 
  cannot add bindings to a locked environment
woodwards commented 6 years ago

Restarting R does not fix it.

johnmchambers commented 6 years ago

It's a bug in juliaAddToPath() (and some other function-level shortcuts).

The workaround is to use the methods of the evaluator directly. So, for example, this works to call a function foo() exported from a module "temp" in the working directory:

ev <- RJulia() ev$AddToPath(getwd()) ev$Using("temp") ev$Call("foo", 1)

(I'll come back to this thread when I get a chance to fix the bugs)

woodwards commented 6 years ago

Thank you, that's excellent, i got that working!

woodwards commented 6 years ago

By the way I am running the example at

https://insightr.wordpress.com/2017/10/18/writing-julia-functions-in-r-with-examples/

johnmchambers commented 6 years ago

A somewhat cleaner way of proceeding in that example (not importing everything via "using") and that also saves some typing is to form the proxies for the Julia functions explicitly.

In my previous example:

ev$AddToPath(getwd()) foo <- JuliaFunction("foo", module = "temp") foo(1)

johnmchambers commented 6 years ago

The problems with juliaAddToPath() and juliaImport()/juliaUsing() should now be solved. You need to install both XR and XRJulia from the revised versions as of March 2 on github.