Created
March 22, 2018 17:55
-
-
Save Non-Contradiction/6ac0472df482610b1c63ebdf60d5b073 to your computer and use it in GitHub Desktop.
juliacall1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dll_file <- system("julia -e \'print(Libdl.dlpath(\"libjulia\"))\'", intern = TRUE) | |
JuliaCall:::juliacall_initialize(dll_file) | |
JuliaCall:::juliacall_cmd('print("1\n")') | |
JuliaCall:::juliacall_cmd("using RCall") | |
JuliaCall:::juliacall_cmd(" | |
function transfer_list(x) | |
rcopy(RObject(Ptr{RCall.VecSxp}(x))) | |
end") | |
JuliaCall:::juliacall_cmd(" | |
function error_msg(e) | |
m = IOBuffer() | |
showerror(m, e) | |
seek(m, 0) | |
readstring(m) | |
end") | |
JuliaCall:::juliacall_cmd(" | |
function error_msg(e, bt) | |
m = IOBuffer() | |
showerror(m, e, bt) | |
seek(m, 0) | |
readstring(m) | |
end") | |
JuliaCall:::juliacall_cmd(' | |
function Rerror(e, bt) | |
s1 = join(["Error happens in Julia.\n"]) | |
s2 = error_msg(e, bt) | |
s = join([s1 s2]) | |
rcall(:simpleError, s) | |
end') | |
JuliaCall:::juliacall_cmd(' | |
function docall(call1) | |
try | |
call = transfer_list(call1) | |
fname = call[:fname]; | |
named_args = call[:named_args] | |
unamed_args = call[:unamed_args] | |
need_return = call[:need_return]; | |
show_value = call[:show_value]; | |
if endswith(fname, ".") | |
fname = chop(fname); | |
f = eval(Main, parse(fname)); | |
r = f.(unamed_args...); | |
else | |
f = eval(Main, parse(fname)); | |
r = f(unamed_args...; named_args...); | |
end | |
if show_value && r != nothing | |
display(r) | |
end | |
# proceed(basic_display_manager) | |
if need_return == "R" | |
RObject(r).p; | |
elseif need_return == "Julia" | |
RObject(JuliaObject(r)).p | |
else | |
RObject(nothing).p; | |
end; | |
catch e | |
Rerror(e, catch_stacktrace()).p; | |
end; | |
end') | |
## If the previous codes run withought segfault, the following ones should be okay. But it is helpful to also try these: | |
JuliaCall:::juliacall_cmd("module AAA end") | |
JuliaCall:::juliacall_cmd("using Suppressor") | |
JuliaCall:::juliacall_cmd(" | |
@suppress begin | |
using RCall | |
end") | |
JuliaCall:::juliacall_cmd(" | |
function exists(x) | |
isdefined(Symbol(x)) | |
end") | |
JuliaCall:::juliacall_cmd(" | |
function eval_string(x) | |
eval(Main, parse(x)) | |
end") | |
JuliaCall:::juliacall_cmd(" | |
function installed_package(pkg_name) | |
string(Pkg.installed(pkg_name)) | |
end") | |
JuliaCall:::juliacall_cmd(' | |
function help(fname) | |
string(eval_string(join(["@doc " fname]))) | |
end') | |
JuliaCall:::juliacall_cmd(" | |
function assign(name, x) | |
eval(Main, Expr(:(=), Symbol(name), x)) | |
end") | |
JuliaCall:::juliacall_cmd(" | |
function str_typeof(x) | |
string(typeof(x)) | |
end") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment