Search code examples
rjuliarcall

Import Julia UnitRange to R using RCall


I would like to import the Julia array including unit range below to R:

Any[1:6, 9, 12, 15]

What I exactly want is something equivalent to this in R:

c(1:6, 9, 12, 15)

Any help will be appreciated.


Solution

  • R"b <- $(collect(flatten(a)))"
    

    Setup:

    using Base.Iterators
    a = [1:6, 9, 12, 15]
    

    Testing

    julia> R"b <- $(collect(flatten(a)))"
    RObject{IntSxp}
    [1]  1  2  3  4  5  6  9 12 15
    

    Please also note that the Julian equivalent of c(1:6, 9, 12, 15) is:

    julia> [1:6..., 9, 12, 15]
    9-element Array{Int64,1}:
      1
      2
      3
      4
      5
      6
      9
     12
     15