Closed Non-Contradiction closed 5 years ago
Push more commits into the branch with a more refined API. Now the example should look like this:
## The above should be safe to go into the function level code.
de <- JuliaCall:::julia_pkg_import("DifferentialEquations",
c("ODEProblem", "solve"))
JuliaCall:::julia_pkg_hook(de,
function(){
JuliaCall::autowrap("DiffEqBase.AbstractODESolution",
fields = c("t","u"))
})
time_range <- function(a, b) JuliaCall::julia_call("tuple",
a, b)
## the user code follows
f <- function(u,p,t) -u
u0 = 0.5
tspan = time_range(0, 1)
prob = de$ODEProblem(f, u0, tspan)
sol = de$solve(prob)
Out of curiousity, does it the call on sol
work for the continuous output, i.e. sol(0.4)
there?
R does not support the callable object syntax. sol is not recognized as a function in R so R will not think sol() is valid. I am not sure whether I can modify the internal of JuliaCall to make sol a function so the syntax is possible. Once the syntax works, the functionality should follows. Or is there any suggestion for a new syntax to mimic callable object syntax in R?
Maybe it can be something like sol$.(0.4)
? I'm fine with any reasonable syntax on this: that's fixable just by documenting it.
With the new commits, sol$.(0.4)
will give the result as sol(0.4)
in julia.
In the commits, $juliaobject$.()` is the syntax to mimic callable objects in Julia, and one cavity is that it doesn't support keyword arguments currently.
I will first merge this PR and get a new release with all the new functionalities and bug fixes. More work will be done in future PRs.
Implement the automatic wrapping functionality for julia functions and packages. Hope it is helpful for package developers using JuliaCall.
Description
Related Issue
Related to https://github.com/JuliaDiffEq/diffeqr/issues/16
Example
The new code implements
JuliaCall:::julia_function
andJuliaCall:::julia_pkg_import
, both unexported currently, which wrap functions and packages automatically. The usage is as follows:In progress.