-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for tuples and better round tripping of named tuples (#515)
* Add support for tuples and better round tripping of named tuples * minor version bump The changes here should not be breaking for most users, but may potentially cause problems for JuliaCall , so we do a breaking version bump.
- Loading branch information
Showing
8 changed files
with
115 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ docs/build | |
docs/gh-pages | ||
docs/site | ||
deps/build.log | ||
lcov.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "RCall" | ||
uuid = "6f49c342-dc21-5d91-9882-a32aef131414" | ||
authors = ["Douglas Bates <[email protected]>", "Randy Lai <[email protected]>", "Simon Byrne <[email protected]>"] | ||
version = "0.13.18" | ||
version = "0.14.0" | ||
|
||
[deps] | ||
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
function sexp(::Type{RClass{:JuliaTuple}}, t::Tuple) | ||
vs = sexp(RClass{:list}, t) | ||
# mark this as originating from a tuple | ||
# for roundtrippping, which downstream JuliaCall | ||
# relies on | ||
# because of the way S3 classes work, this doesn't break anything on the R side | ||
# and strictly adds more information that we can take advantage of | ||
setattrib!(vs, :class, sexp("JuliaTuple")) | ||
vs | ||
end | ||
|
||
function sexp(::Type{RClass{:list}}, t::Tuple) | ||
n = length(t) | ||
vs = protect(allocArray(VecSxp,n)) | ||
try | ||
for (i, v) in enumerate(t) | ||
vs[i] = v | ||
end | ||
finally | ||
unprotect(1) | ||
end | ||
vs | ||
end | ||
|
||
sexpclass(::Tuple) = RClass{:JuliaTuple} | ||
|
||
rcopytype(::Type{RClass{:JuliaTuple}}, x::Ptr{VecSxp}) = Tuple | ||
|
||
function rcopy(::Type{T}, s::Ptr{VecSxp}) where {T <: Tuple} | ||
protect(s) | ||
try | ||
T(rcopy(el) for el in s) | ||
finally | ||
unprotect(1) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
t = ("a", 1, [1,2]) | ||
r = RObject(t) | ||
@test r isa RObject{VecSxp} | ||
@test length(r) == length(t) | ||
@test rcopy(Tuple, r) == t | ||
@test rcopy(typeof(t), r) == t | ||
@test rcopy(r) == t | ||
@test rcopy(Array, r) == collect(t) | ||
r[3] = 2.5 | ||
me_test = @test_throws MethodError rcopy(typeof(t), r) | ||
@test me_test.value.f === convert | ||
@test me_test.value.args == (Vector{Int64}, 2.5) | ||
|
||
@test rcopy(RObject(sexp(RClass{:list}, t))) isa Vector{Any} | ||
@test rcopy(RObject(t)) isa typeof(t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5d0ddeb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
5d0ddeb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/98492
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
5d0ddeb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
Release notes:
5d0ddeb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request updated: JuliaRegistries/General/98492
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: