Skip to content

Commit

Permalink
copy list to OrderedDict by default
Browse files Browse the repository at this point in the history
also sanitize variable names by replaceing dots
  • Loading branch information
randy3k committed Nov 14, 2017
1 parent b2b4a39 commit f3d0613
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/convert/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,19 @@ end
# VecSxp
rcopy(::Type{Array}, s::Ptr{VecSxp}) = rcopy(Array{Any}, s)
rcopy(::Type{Vector}, s::Ptr{VecSxp}) = rcopy(Vector{Any}, s)
function rcopy(::Type{A}, s::Ptr{VecSxp}) where A<:Associative
function rcopy(::Type{A}, s::Ptr{VecSxp}; sanitize::Bool=true) where A<:Associative
protect(s)
local a
try
a = A()
K = keytype(a)
V = valtype(a)
for (k,v) in zip(getnames(s),s)
a[rcopy(K,k)] = rcopy(V,v)
for (k, v) in zip(getnames(s), s)
if sanitize && (K <: AbstractString || K <: Symbol)
a[K(replace(rcopy(String, k), ".", "_"))] = rcopy(V, v)
else
a[rcopy(K, k)] = rcopy(V, v)
end
end
finally
unprotect(1)
Expand Down
2 changes: 1 addition & 1 deletion src/convert/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function rcopytype(::Type{RClass{Sym}}, s::Ptr{VecSxp}) where Sym
elseif isnull(getnames(s))
Array{Any}
else
Dict{Symbol,Any}
OrderedDict{Symbol,Any}
end
end

Expand Down

0 comments on commit f3d0613

Please sign in to comment.