-
Notifications
You must be signed in to change notification settings - Fork 59
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
base: main
Are you sure you want to change the base?
raise julia errors #525
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 | ||||||||||
|
||||||||||
|
||||||||||
|
@@ -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()) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
finally | ||||||||||
unprotect(nprotect) | ||||||||||
RCall.unprotect(nprotect) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
end | ||||||||||
clos | ||||||||||
end | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.