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

Error when using julia_eval: invalid first argument #251

Open
tom-metherell opened this issue Jan 30, 2025 · 0 comments
Open

Error when using julia_eval: invalid first argument #251

tom-metherell opened this issue Jan 30, 2025 · 0 comments

Comments

@tom-metherell
Copy link

Hi there,

I'm trying to add functionality to the package Mice.jl to allow objects to be converted into the equivalent from the R package mice. I made an extension for this.

This works fine when trying to export the Julia object into R using @rput:

using Pkg

Pkg.add(url = "https://github.com/tom-metherell/Mice.jl.git")

using DataFrames, Mice, Random, RCall

df = DataFrame(
    a = Vector{Union{Missing, Int}}(randperm(20)),
    b = Vector{Union{Missing, Float64}}(randperm(20)),
    c = Vector{Union{Missing, String}}(rand(["a", "b", "c"], 20)),
    d = Vector{Union{Missing, Bool}}(rand(Bool, 20))
)

for col in axes(df, 2)
    df[rand(1:20, 1), col] .= missing
end

imputedData = mice(df, m = 1, iter = 1)

@rput imputedData

However, when I am working from R and try to retrieve the Julia object using julia_eval, I get an error:

library(JuliaCall)
julia_setup()

julia_command('Pkg.add(url = "https://github.com/tom-metherell/Mice.jl.git")')

julia_library("DataFrames")
julia_library("Mice")
julia_library("Random")
julia_library("RCall")

julia_command('df = DataFrame(a = Vector{Union{Missing, Int}}(randperm(20)), b = Vector{Union{Missing, Float64}}(randperm(20)), c = Vector{Union{Missing, String}}(rand(["a", "b", "c"], 20)), d = Vector{Union{Missing, Bool}}(rand(Bool, 20)))')
julia_command("for col in axes(df, 2); df[rand(1:20, 1), col] .= missing; end")

julia_command("imputedData = mice(df, m = 1, iter = 1)")

julia_eval("imputedData")

Error in .julia$do.call_(jcall) :
invalid first argument, must be vector (list or atomic)


Do you have any idea how I might be able to fix this? I'm a bit confused as to why everything works okay if I start in Julia, but if I start in R I get this error, even though I'm trying to convert an object from Julia to R in both cases.

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant