Skip to content

Commit

Permalink
Conversion of R data.frame with matrix columns (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
Non-Contradiction authored and randy3k committed Jan 6, 2019
1 parent 73d9410 commit 06a877d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/convert/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function rcopy(::Type{T}, s::Ptr{VecSxp};
if normalizenames
vnames = [Symbol(replace(string(v), '.' => '_')) for v in vnames]
end
DataFrame([rcopy(AbstractArray, c) for c in s], vnames)
DataFrame([vec(rcopy(AbstractArray, c)) for c in s], vnames)
end

## DataFrame to sexp conversion.
Expand Down
7 changes: 6 additions & 1 deletion test/convert/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ attenu = rcopy(DataFrame,reval(:attenu))
@test size(attenu) == (182,5)
@test rcopy(rcall(:dim,RObject(attenu))) == [182,5]
@test rcopy(rcall(:dim, RObject(attenu[1:2, :]))) == [2, 5]
@test rcopy(rcall(:dim, RObject(view(attenu, 1:2)))) == [2, 5]
@test rcopy(rcall(:dim, RObject(view(attenu, 1:2, :)))) == [2, 5]
dist = attenu[:dist]
@test isa(dist,Array{Float64})
station = attenu[:station]
Expand All @@ -19,3 +19,8 @@ station = attenu[:station]
# issue #186
df = R"""data.frame(dates = as.Date(c("2017-04-14", "2014-04-17")))"""
@test eltype(rcopy(df)[:dates]) == Date

# issue #290
R"a = data.frame(a1 = rep(1,3)); a$a2 = matrix(2,3,1)"
R"b = data.frame(a1 = rep(1,3)); b$a2 = rep(2,3)"
@test rcopy(R"a") == rcopy(R"b")

0 comments on commit 06a877d

Please sign in to comment.