diff --git a/src/RCall.jl b/src/RCall.jl index 8f7d3bf4..05e36b6a 100644 --- a/src/RCall.jl +++ b/src/RCall.jl @@ -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")) diff --git a/src/convert-base.jl b/src/convert-base.jl index 71778a48..b852128d 100644 --- a/src/convert-base.jl +++ b/src/convert-base.jl @@ -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) diff --git a/src/convert-default.jl b/src/convert-default.jl index c3bd4c0d..399f44fc 100644 --- a/src/convert-default.jl +++ b/src/convert-default.jl @@ -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 diff --git a/src/functions.jl b/src/functions.jl index 06782675..f244f251 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -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 diff --git a/test/basic.jl b/test/basic.jl index 1b2486f7..8b7d4eab 100644 --- a/test/basic.jl +++ b/test/basic.jl @@ -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] diff --git a/test/conversion.jl b/test/conversion.jl index c984e722..ed755fbe 100644 --- a/test/conversion.jl +++ b/test/conversion.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index ab43dfb7..f2a03111 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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()