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: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 19 additions & 9 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,24 +127,31 @@ 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
args = protect(sexp_arglist_dots())
args = RCall.protect(RCall.sexp_arglist_dots())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args = RCall.protect(RCall.sexp_arglist_dots())
args = protect(sexp_arglist_dots())

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to qualify things from RCall when executing within RCall. (If you were overwriting these methods from an external definition, then you do need that qualification.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for all the changes. yes indeed I was previously overwriting it but as this got discouraged like an error in julia 1.10 I switched to forking RCall. These were apparently some leftovers

nprotect += 1
lang = rlang_p(:function, args, body)
clos = reval_p(lang)
lang = RCall.rlang_p(:function, args, body)
clos = RCall.reval_p(lang)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lang = RCall.rlang_p(:function, args, body)
clos = RCall.reval_p(lang)
lang = rlang_p(:function, args, body)
clos = reval_p(lang)

finally
unprotect(nprotect)
RCall.unprotect(nprotect)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RCall.unprotect(nprotect)
unprotect(nprotect)

end
clos
end
Expand Down