Skip to content

If julia functions which was brought to R throws an error, no real error is thrown, but an error object is returned #216 #508

Open
@schlichtanders

Description

@schlichtanders

I created an issue at JuliaCall however after a first inspection, I think it is actually an RCall issue.

Concretely something in the following is not raising julia errors when run on R. Also the stacktrace is not reported.

RCall.jl/src/callback.jl

Lines 122 to 147 in 69c22dd

"""
Wrap a callable Julia object `f` an a R `ClosSxpPtr`.
Constructs the following R code
function(...) .External(juliaCallback, fExPtr, ...)
"""
function sexp(::Type{RClass{:function}}, f)
fptr = protect(sexp(RClass{:externalptr}, f))
body = protect(rlang_p(Symbol(".External"),
juliaCallback,
fptr,
Const.DotsSymbol))
nprotect = 2
local clos
try
args = protect(sexp_arglist_dots())
nprotect += 1
lang = rlang_p(:function, args, body)
clos = reval_p(lang)
finally
unprotect(nprotect)
end
clos
end

Helpful steps to provide error support

Looking into JuliaCall's error handling, there are two places:

  1. on JuliaCall julia side the following try catch converts a julia error to an R object https://github.com/Non-Contradiction/JuliaCall/blob/c05473bea78a0197c639f7e82ab1c6f2e943e1cc/inst/julia/setup.jl#L165-L194
function docall(call1)
    try
        # ...
    catch e
        Rerror(e, stacktrace(catch_backtrace())).p;
    end;
end
  1. on JuliaCall R side the following intercepts these R objects and raises them as R errors https://github.com/Non-Contradiction/JuliaCall/blob/c05473bea78a0197c639f7e82ab1c6f2e943e1cc/R/interface.R#L76-L78
    r <- .julia$do.call_(jcall)

    if (inherits(r, "error")) stop(r)

Both these steps would need to be replicated inside the conversion of a Julia Function to an R function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions