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

raise julia errors #525

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ const juliaCallback = RObject{ExtPtrSxp}()
function setup_callbacks()
julia_extptr_callback_ptr = @cfunction(julia_extptr_callback,Ptr{UnknownSxp},(Ptr{ListSxp},))
juliaCallback.p = makeNativeSymbolRef(julia_extptr_callback_ptr)

# helper to throw Julia errors on R side
reval("...stop_if_error <- function (obj) if (inherits(obj, 'error')) stop(obj) else obj")
end


Expand All @@ -124,15 +127,22 @@ Wrap a callable Julia object `f` an a R `ClosSxpPtr`.

Constructs the following R code

function(...) .External(juliaCallback, fExPtr, ...)
function(...) ...stop_if_error(.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))
body = protect(
rlang_p(
Symbol("...stop_if_error"),
rlang_p(
Symbol(".External"),
juliaCallback,
fptr,
Const.DotsSymbol
)
)
)
nprotect = 2
local clos
try
Expand Down
Loading