Supported Conversions

RCall supports conversions to and from most base Julia types and popular Statistics packages, e.g., DataFrames, CategoricalArrays and AxisArrays.

Base Julia Types

# Julia -> R
a = robject(1)
RObject{IntSxp}
[1] 1
# R -> Julia
rcopy(a)
1
# Julia -> R
a = robject([1.0, 2.0])
RObject{RealSxp}
[1] 1 2
# R -> Julia
rcopy(a)
2-element Vector{Float64}:
 1.0
 2.0

Dictionaries

# Julia -> R
d = Dict(:a => 1, :b => [4, 5, 3])
r = robject(d)
RObject{VecSxp}
$a
[1] 1

$b
[1] 4 5 3

# R -> Julia
rcopy(r)
OrderedCollections.OrderedDict{Symbol, Any} with 2 entries:
  :a => 1
  :b => [4, 5, 3]

Date

# Julia -> R
d = Date(2012, 12, 12)
r = robject(d)
RObject{RealSxp}
[1] "2012-12-12"
# R -> Julia
rcopy(r)
2012-12-12

DateTime

# julia -> R
d = DateTime(2012, 12, 12, 12, 12, 12)
r = robject(d)
RObject{RealSxp}
[1] "2012-12-12 12:12:12 UTC"
# R -> Julia
rcopy(r)
2012-12-12T12:12:12

DataFrames

d = DataFrame([[1.0, 4.5, 7.0]], [:x])
# Julia -> R
r = robject(d)
RObject{VecSxp}
    x
1 1.0
2 4.5
3 7.0
# R -> Julia
rcopy(r)

3 rows × 1 columns

x
Float64
11.0
24.5
37.0

In default, the column names of R data frames are normalized such that foo.bar would be replaced by foo_bar.

rcopy(R"data.frame(a.b = 1:3)")

3 rows × 1 columns

a_b
Int64
11
22
33

To avoid the normalization, use normalizenames option.

rcopy(R"data.frame(a.b = 1:10)"; normalizenames = false)

10 rows × 1 columns

a.b
Int64
11
22
33
44
55
66
77
88
99
1010

AxisArrays

# Julia -> R
aa = AxisArray([1,2,3], Axis{:id}(["a", "b", "c"]))
r = robject(aa)
RObject{IntSxp}
id
a b c 
1 2 3 
# R -> Julia
rcopy(AxisArray, r)
1-dimensional AxisArray{Int64,1,...} with axes:
    :id, ["a", "b", "c"]
And data, a 3-element Vector{Int64}:
 1
 2
 3