Skip to content

Commit

Permalink
add var_str macro to fix #71, fix remaining deprecation warnings in t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
simonbyrne committed Oct 14, 2015
1 parent 9e9c054 commit ea119a2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/RCall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export RObject,
globalEnv,
rcopy, rparse, rprint, reval, rcall, rlang,
isNA, anyNA, isFactor, isOrdered,
@rimport, @rusing, @rput, @rget
@rimport, @rusing, @rput, @rget, @var_str


if isfile(joinpath(dirname(@__FILE__),"..","deps","deps.jl"))
Expand Down
2 changes: 1 addition & 1 deletion src/convert-base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ rcopy{T<:AbstractString}(::Type{T},s::CharSxpPtr) = convert(T, bytestring(unsafe
rcopy(::Type{Symbol},s::CharSxpPtr) = symbol(rcopy(AbstractString,s))


@doc "Create a `StrSxp` from a `String`"->
@doc "Create a `StrSxp` from an `AbstractString`"->
sexp(::Type{StrSxp}, s::CharSxpPtr) =
ccall((:Rf_ScalarString,libR),Ptr{StrSxp},(CharSxpPtr,),s)

Expand Down
4 changes: 2 additions & 2 deletions src/convert-default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
`rcopy` copies the contents of an R object into a corresponding canonical Julia type.
""" ->
rcopy(s::SymSxpPtr) = rcopy(Symbol,s)
rcopy(s::CharSxpPtr) = rcopy(String,s)
rcopy(s::CharSxpPtr) = rcopy(AbstractString,s)

function rcopy(s::StrSxpPtr)
if anyNA(s)
rcopy(DataArray,s)
elseif length(s) == 1
rcopy(String,s)
rcopy(AbstractString,s)
else
rcopy(Array,s)
end
Expand Down
7 changes: 7 additions & 0 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ rcall_p(f,args...;kwargs...) = reval_p(rlang_p(f,args...;kwargs...))
if VERSION >= v"v0.4-"
@compat Base.call{S<:Union{SymSxp,LangSxp,FunctionSxp}}(f::RObject{S},args...;kwargs...) = rcall(f,args...;kwargs...)
end

@doc """
Returns a variable named "str". Useful for passing keyword arguments containing dots.
"""->
macro var_str(str)
esc(symbol(str))
end
4 changes: 4 additions & 0 deletions test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ y = "foo"

@test sprint(io -> rprint(io,RObject([1,2,3]))) == "[1] 1 2 3\n"

@test_approx_eq rcopy(rcall(:besselI, 1.0, 2.0)) besseli(2.0,1.0)
@test_approx_eq rcopy(rcall(:besselI, 1.0, 2.0, var"expon.scaled"=true)) besselix(2.0,1.0)


# callbacks
function testfn(x,y;a=3,b=4)
[x;y;a;b]
Expand Down
2 changes: 1 addition & 1 deletion test/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ r = RObject(false)
@test rcopy(r) === false
@test r[1] === convert(Cint,0)

v = randbool(10)
v = bitrand(10)
r = RObject(v)
@test isa(r,RObject{LglSxp})
@test length(r) == length(v)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Base.Test
hd = homedir()
pd = Pkg.dir()

using RCall
using Compat

# https://github.com/JuliaStats/RCall.jl/issues/68
@test hd == homedir()
@test pd == Pkg.dir()
Expand Down

0 comments on commit ea119a2

Please sign in to comment.