Skip to content

Error when using julia_eval: invalid first argument #251

Description

@tom-metherell

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions