Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using RCall from Julia embedded in R, things like R REPL mode are not set up. #201

Closed
Non-Contradiction opened this issue Sep 8, 2017 · 13 comments

Comments

@Non-Contradiction
Copy link
Contributor

I'm currently developing an R package JuliaCall which aims at embedding julia in R. https://github.com/Non-Contradiction/JuliaCall

And in the init() function of setup.jl of RCall, there is something like this:

if !Rinited
   ...................
    # R gui eventloop
    isinteractive() && rgui_init()
    # R REPL mode
    isdefined(Base, :active_repl) &&
        isinteractive() && typeof(Base.active_repl) != Base.REPL.BasicREPL &&
            RPrompt.repl_init(Base.active_repl)
end

Since julia is already embedded in R, Rinited is true, and the code for REPL mode will not be executed. So if I want to use R REPL mode provided by RCall, I have to RCall.RPrompt.repl_init(Base.active_repl) myself like this:

Is there any reason for not doing rgui_init() and setting REPL mode when R is already started besides not doing repetitive work? Could we use other ways to check whether R REPL mode is set and gui_init() has been done?

@randy3k
Copy link
Member

randy3k commented Sep 9, 2017

You are probably correct. Would you submit the PR?

@randy3k
Copy link
Member

randy3k commented Sep 9, 2017

It is an interesting project.

Btw, I am on the master branch of JuliaCall and it does not seem to be working for me.
screen shot 2017-09-09 at 2 44 28 pm

EDIT: works now after running julia_setup()

@Non-Contradiction
Copy link
Contributor Author

Yes, I' m going to submit a PR, although I'm not quite familiar with the julia workflow of developing packages.

@Non-Contradiction
Copy link
Contributor Author

Sorry the screenshot is not complete. julia_setup() needs to use first to do some setup like this:

library(JuliaCall)
julia <- julia_setup()
julia_console()

@randy3k
Copy link
Member

randy3k commented Sep 9, 2017

I figured it out. Amazing package.

@randy3k
Copy link
Member

randy3k commented Sep 9, 2017

I also realized I could embedde julia in an R session embedded in julia.

julia> using RCall
WARNING: Method definition ==(Base.Nullable{S}, Base.Nullable{T}) in module Base at nullable.jl:238 overwritten in module NullableArrays at /Users/Randy/.julia/v0.6/NullableArrays/src/operators.jl:99.

julia> R"library(JuliaCall); julia_setup(); julia_console()"
WARNING: RCall.jl: Julia at location /Applications/Julia-0.6.app/Contents/Resources/julia/bin will be used.
Julia version 0.6.0 found.
Julia initiation...
Finish Julia initiation.
Loading setup script for JuliaCall...
Finish loading setup script for JuliaCall.
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.0 (2017-06-19 13:05 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-apple-darwin13.4.0

julia>

Though, arguably, it is useless.

@randy3k
Copy link
Member

randy3k commented Sep 9, 2017

I reckon that we could use

any(:prompt in fieldnames(m) && m.prompt == "R> " for m in mirepl.interface.modes)

to check if the repl has been initilaized.

@Non-Contradiction
Copy link
Contributor Author

Yes, it works. Although it seems that I need to do more work on the JuliaCall side. In my test, using RCall in julia_console() won't trigger RCall.__init__(), which is kind of strange. I probably should using RCall on the startup of julia_console() and do the setup.

@randy3k
Copy link
Member

randy3k commented Sep 9, 2017

It is expected that using RCall does not trigger RCall.__init__(). It is common to have multiple using RCall statements in a Julia session, __init__() will only be triggered when a package is loaded first time.

@randy3k
Copy link
Member

randy3k commented Sep 9, 2017

You may also need to run rgui_start and rgui_stop() before and after julia_console().

@randy3k
Copy link
Member

randy3k commented Sep 9, 2017

You could just execute RCall.__init__() in the setup.jl.

@Non-Contradiction
Copy link
Contributor Author

When JuliaCall sources setup.jl in embedded julia, julia is not in the interactive use. So even RCall.__init__() explicitly, things like REPL won't set up. Do I understand correctly?

@randy3k
Copy link
Member

randy3k commented Sep 9, 2017

Ai, you are correct. In fact, we shouldn't call __init__() explicitly. It may break other things.

Perhaps, you should just execute repl_init() when ! repl_inited().

@randy3k randy3k closed this as completed in e5bc6f4 Sep 9, 2017
randy3k pushed a commit that referenced this issue Sep 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants