juliainterop / rcall.jl Goto Github PK
View Code? Open in Web Editor NEWCall R from Julia
License: Other
Call R from Julia
License: Other
Thanks for RCall it looks very useful. I followed the installation steps in the README on a fresh Julia 0.3.4 on Mac OS X Yosemite with all packages updated but then get this when trying to load RCall:
julia> using RCall
Warning: error initializing module RCall:
ErrorException("type cannot be constructed")
The deps.jl file looks fine except for the LD_LIBRARY_PATH:
feldt:~/feldt/bin$ cat /Users/feldt/.julia/v0.3/RCall/deps/deps.jl
# This is an auto-generated file; do not edit
const libR="/usr/local/Cellar/r/3.1.1/R.framework/Resources/lib/libR.dylib"
ENV["R_HOME"]="/usr/local/Cellar/r/3.1.1/R.framework/Resources"
ENV["R_DOC_DIR"]="/usr/local/Cellar/r/3.1.1/R.framework/Resources/doc"
ENV["R_INCLUDE_DIR"]="/usr/local/Cellar/r/3.1.1/R.framework/Resources/include"
ENV["R_SHARE_DIR"]="/usr/local/Cellar/r/3.1.1/R.framework/Resources/share"
ENV["LD_LIBRARY_PATH"]=""
so I changed it to
ENV["LD_LIBRARY_PATH"]="/usr/local/Cellar/r/3.1.1/R.framework/Resources/lib"
but with same error. Any ideas on what is wrong here? Thanks in advance.
Here is my code:
using RCall
R.library(:ggplot2)
g = globalEnv
x=linspace(-11,8,2000)
y = randn(2000)
g[:x]=x
g[:y]=y
The following line is fine
"""pdf();plot(x=x,y=y, type="l");dev.off()""" |> rparse|>reval
But the following line will cause a core dump
"""pdf();print(ggplot()+geom_line(aes(x=x, y=y)));dev.off()""" |> rparse|>reval
The error message is
Error: VECTOR_ELT() can only be applied to a 'list', not a 'character'
*** stack smashing detected ***: julia terminated
I also tried something else, like
"""plot(x=x,y=y, type="l")""" |> rparse|>reval
will give me a window of graph. But I cannot close the window unless I run
"""dev.off()""" |> rparse|>reval
For ggplot2
case I also tried
"""pdf();print(ggplot()+geom_line(aes(x=x, y=y)))""" |> rparse|>reval
"""dev.off()""" |> rparse|>reval
Then everything is fine. I replicated the bug on two different Linux machine.
julia> versioninfo()
Julia Version 0.4.0-dev+3172
Commit 456b85a* (2015-02-06 21:24 UTC)
Platform Info:
System: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i5-2467M CPU @ 1.60GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3
And
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
P.S. For ggplot2
case, if I do not use print
, it will return a broken file.
I cannot identify the issue, it seems it has something to do with IJulia.jl
. But I cannot figure it out. I am running the nightly build on Mac OS via command line.
PS: it is working on v.0.3.7
ERROR: LoadError: LoadError: error compiling anonymous: unsupported or misplaced expression "import" in function anonymous
in include at /opt/local/julia-dev/lib/julia/sys.dylib
in include_from_node1 at /opt/local/julia-dev/lib/julia/sys.dylib
in include at /opt/local/julia-dev/lib/julia/sys.dylib
in include_from_node1 at /opt/local/julia-dev/lib/julia/sys.dylib
in reload_path at /opt/local/julia-dev/lib/julia/sys.dylib
in _require at /opt/local/julia-dev/lib/julia/sys.dylib
in require at /opt/local/julia-dev/lib/julia/sys.dylib
while loading /Users/Randy/.julia/v0.4/RCall/src/IJulia.jl, in expression starting on line 3
while loading /Users/Randy/.julia/v0.4/RCall/src/RCall.jl, in expression starting on line 75
I believe that we have to somehow preserve the object created by Rf_allocVector.
It should be fine if this R object is blinded to some variable in some environment. But it may not be always the case.
For example, the following produces segfault
x = RCall.asSEXP([1:10^8])
for i in 1:10
Reval(Rparse("gc()"))
end
Rprint(x)
In attempting to execute graphics.ipynb on my Windows test environment (64-bit Windows, 32-bit Julia v0.4.0-rc1, 32-bit R 3.2.2), the current In[4]:
example makes a call to rplot_set(MIME("image/svg+xml")
, which generated the following error message on my machine:
LoadError: UndefVarError: rplot_set not defined
while loading In[4], in expression starting on line 1
Is the notebook example stale and in need of update, or should this function actually be present in the RCall namespace and went missing at some point?
The RCall namespace currently includes the following:
julia> RCall.
@rget __init__ rBraceSymbol
@rimport allocArray rBracket2Symbol
@rput allocList rBracketSymbol
@rusing anyNA rClassSymbol
AnySxp askYesNoCancel rDeviceSymbol
AnySxpPtr attributes rDimNamesSymbol
BcodeSxp bound rDimSymbol
BcodeSxpPtr callJuliaExtPtr rDollarSymbol
BuiltinSxp car rDotsSymbol
BuiltinSxpPtr cdr rDoubleColonSymbol
CharSxp dataptr rDropSymbol
CharSxpPtr decrefExtPtr rEmptyEnv
ClosSxp errorBuffer rGlobalEnv
ClosSxpPtr eval rJuliaCallback
CplxSxp eventCallBack rLastvalueSymbol
CplxSxpPtr getAttrib rLevelsSymbol
DotSxp getClass rMissingArg
DotSxpPtr getNames rModeSymbol
EnvSxp globalEnv rNaInt
EnvSxpPtr ijulia_cleanup rNaReal
ExprSxp ijulia_displayfile rNaRmSymbol
ExprSxpPtr ijulia_displayplots rNaString
ExtPtrSxp ijulia_file_dir rNameSymbol
ExtPtrSxpPtr ijulia_init rNamesSymbol
FunctionSxp ijulia_mime rNamespaceEnvSymbol
FunctionSxpPtr ijulia_setdevice rNilValue
IntSxp isArray rPackageSymbol
IntSxpPtr isComplex rPreviousSymbol
LangSxp isEnvironment rQuoteSymbol
LangSxpPtr isExpression rRowNamesSymbol
LglSxp isFactor rSeedsSymbol
LglSxpPtr isFrame rSortListSymbol
ListSxp isFree rSourceSymbol
ListSxpPtr isFunction rSpecSymbol
NAel isInteger rTripleColonSymbol
NilSxp isLanguage rUnboundValue
NilSxpPtr isList rcall
PairListSxp isLogical rcall_p
PairListSxpPtr isMatrix rcopy
PromSxp isNA rdevicename
PromSxpPtr isNewList rdot_Method
RObject isNull rdot_defined
RStart isNumber rdot_packageName
RawSxp isNumeric rdot_target
RawSxpPtr isObject registerFinalizer
RealSxp isOrdered release
RealSxpPtr isPairListSxp reserved
Rinstance isPrimitiveSxp reval
Rproc isReal reval_p
S4Sxp isS4 rgui_start
S4SxpPtr isString rgui_stop
SpecialSxp isSymbol rlang
SpecialSxpPtr isTs rlang_formula
StrSxp isUnordered rlang_p
StrSxpPtr isUnsorted rparse
Sxp isUserBinop rparse_p
SxpHead isValidString rprint
SxpPtr isValidStringF rwrap
SxpPtrInfo isVector setAttrib!
SymSxp isVectorAtomicSxp setClass!
SymSxpPtr isVectorListSxp setNames!
UnknownSxpPtr isVectorizable setcar!
VecSxp jtypExtPtrs setcdr!
VecSxpPtr libR settag!
VectorAtomicSxp makeExternalPtr sexp
VectorAtomicSxpPtr makeNativeSymbol sexp_arglist_dots
VectorListSxp pJuliaCallback sexpnum
VectorListSxpPtr pJuliaDecref tag
VectorNumericSxp preserve timeout
VectorNumericSxpPtr printBuffer typs
VectorSxp process_events unprotect
VectorSxpPtr protect unsafe_array
WeakRefSxp rBaseSymbol unsafe_vec
WeakRefSxpPtr rBlankScalarString voffset
__META__ rBlankString writeConsoleEx
Pkg.test("Rcall")
fails on Mac OSX with the error:
Running tests:
* basic.jl ...
ERROR: LoadError: LoadError: test failed: "BJsales" == "airmiles"
in expression: rcopy(lsd[2]) == "airmiles"
in error at /Applications/Julia-0.4.1.app/Contents/Resources/julia/lib/julia/sys.dylib
in default_handler at test.jl:30
in do_test at test.jl:53
in include at /Applications/Julia-0.4.1.app/Contents/Resources/julia/lib/julia/sys.dylib
in include_from_node1 at /Applications/Julia-0.4.1.app/Contents/Resources/julia/lib/julia/sys.dylib
[inlined code] from /Users/ranjan/.julia/v0.4/RCall/test/runtests.jl:21
in anonymous at no file:0
in include at /Applications/Julia-0.4.1.app/Contents/Resources/julia/lib/julia/sys.dylib
in include_from_node1 at /Applications/Julia-0.4.1.app/Contents/Resources/julia/lib/julia/sys.dylib
in process_options at /Applications/Julia-0.4.1.app/Contents/Resources/julia/lib/julia/sys.dylib
in _start at /Applications/Julia-0.4.1.app/Contents/Resources/julia/lib/julia/sys.dylib
while loading /Users/ranjan/.julia/v0.4/RCall/test/basic.jl, in expression starting on line 8
while loading /Users/ranjan/.julia/v0.4/RCall/test/runtests.jl, in expression starting on line 18
================================[ ERROR: RCall ]================================
failed process: Process(`/Applications/Julia-0.4.1.app/Contents/Resources/julia/bin/julia --check-bounds=yes --code-coverage=none --color=yes /Users/ranjan/.julia/v0.4/RCall/test/runtests.jl`, ProcessExited(1)) [1]
================================================================================
ERROR: RCall had test errors
in error at /Applications/Julia-0.4.1.app/Contents/Resources/julia/lib/julia/sys.dylib
in test at pkg/entry.jl:803
in anonymous at pkg/dir.jl:31
in cd at file.jl:22
in cd at pkg/dir.jl:31
in test at pkg.jl:71
Here's my versioninfo()
Julia Version 0.4.1
Commit cbe1bee* (2015-11-08 10:33 UTC)
Platform Info:
System: Darwin (x86_64-apple-darwin13.4.0)
CPU: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.3
I haven't dug into exactly why this is failing on v"0.4.0-dev" and not on version 0.3.8 but
~/.julia/v0.4/RCall/deps$ julia -e 'println(versioninfo()); include("build.jl")'
Julia Version 0.3.8
Commit 79599ad (2015-04-30 23:40 UTC)
Platform Info:
System: Linux (x86_64-linux-gnu)
CPU: AMD Athlon(tm) II X4 635 Processor
WORD_SIZE: 64
BLAS: libopenblas (NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Barcelona)
LAPACK: liblapack.so.3
LIBM: libopenlibm
LLVM: libLLVM-3.3
nothing
bates@thin40:~/.julia/v0.4/RCall/deps$ julia4 -e 'println(versioninfo()); include("build.jl")'
Julia Version 0.4.0-dev+4850
Commit c260ea9* (2015-05-15 15:14 UTC)
Platform Info:
System: Linux (x86_64-linux-gnu)
CPU: AMD Athlon(tm) II X4 635 Processor
WORD_SIZE: 64
BLAS: libopenblas (NO_AFFINITY BARCELONA)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.6.0
nothing
ERROR: LoadError: Unable to locate libR.so
Try setting R_HOME, and re-run Pkg.build("RCall").
in error at ./error.jl:21
in anonymous at ./no file:44
in include at ./boot.jl:252
in include_from_node1 at ./loading.jl:134
in process_options at ./client.jl:288
in _start at ./client.jl:409
while loading /home/bates/.julia/v0.4/RCall/deps/build.jl, in expression starting on line 3
At present the vec
methods preserve the R storage using R_PreserveObject
. If vec
is called frequently then garbage collection of the Julia objects becomes slow because R_ReleaseObject
does a linear search on a long vector.
One way around this is to have the evaluation of a name or expression create the appropriate Julia object and copy the contents of the R object into Julia storage. This seems like a good idea to me right now but I may have missed good reasons to keep things as they are.
Opinions?
julia> using RCall
ERROR: LoadError: LoadError: Timer(f) is deprecated. Use Timer(f, delay, repeat) instead.
in call at ./deprecated.jl:524
in include at ./boot.jl:254
in include_from_node1 at ./loading.jl:133
in include at ./boot.jl:254
in include_from_node1 at ./loading.jl:133
in reload_path at ./loading.jl:157
in _require at ./loading.jl:69
in require at ./loading.jl:52
while loading /home/bates/.julia/v0.4/RCall/src/eventloop.jl, in expression starting on line 16
while loading /home/bates/.julia/v0.4/RCall/src/RCall.jl, in expression starting on line 77
julia> versioninfo()
Julia Version 0.4.0-dev+5383
Commit 993adea (2015-06-15 08:27 UTC)
Platform Info:
System: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
WORD_SIZE: 64
BLAS: libmkl_rt
LAPACK: libmkl_rt
LIBM: libimf
LLVM: libLLVM-3.6.1
Unfortunately, I don't know enough about the eventloop to investigate this.
ttt = ccall((:R_ParseVector,RCall.libR),Ptr{Void},(Ptr{Void},Cint,Ptr{Cint},Ptr{Void}),RCall.mkString("library(lme4)"),1,status,ff)
Hi,
Is it possible to copy simple arrays (matrices/vectors) from Julia to R, let R do some work and copy the result back?
In the documentation I have only found examples where R objects are copied to Julia.
It would be useful to be able to call Julia functions from within R, similar to PyCall's facility, e.g.
rcall(:plot, x -> x*x)
However there doesn't appear to be an immediately obvious way to call C function pointers from R, at least as far as I could tell. Any ideas?
It would be useful to be able to rprint
to different IO objects (at the very least, we could then define nicer show
methods for SEXPREC objects).
There doesn't seem to be a convenient way to get this directly from R, so I guess we have to use redirect_stdout
?
follow up #6
When a R memory is referenced by a julia variable, It may be always necessary to execute PreserveObject
when rawvector
is called.
using RCall
fails on Julia 0.4:
ERROR: LoadError: LoadError: Timer(f) is deprecated. Use Timer(f, delay, repeat) instead.
in call at deprecated.jl:557
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/diego/.julia/v0.4/RCall/src/eventloop.jl, in expression starting on line 16
while loading /home/diego/.julia/v0.4/RCall/src/RCall.jl, in expression starting on line 77
julia> versioninfo()
Julia Version 0.4.0-rc2
Commit fa52609* (2015-09-18 17:51 UTC)
Platform Info:
System: Linux (x86_64-unknown-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-2650L v2 @ 1.70GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3
Currently all the objects in an R package are converted to LangSxp
's by @rimport
, which is not appropriate for R objects that are vectors, in the R sense. There should at least be a check on whether the name evaluates to a CLOSXP before conversion. I'll take a look at this.
julia> using RCall
julia> @rimport MASS as m
julia> typeof m.s
sammon ships shrimp snails steam stormer survey synth.tr
select shoes shuttle stdres stepAIC studres synth.te
julia> typeof(m.shuttle)
LangSxp (constructor with 2 methods)
julia> rcall(m.shuttle)
Error: attempt to apply non-function
ERROR: Error occurred in R_tryEval
in reval at /home/bates/.julia/v0.3/RCall/src/iface.jl:5
in reval at /home/bates/.julia/v0.3/RCall/src/iface.jl:16
Fantastic package! I was hoping to wrap some R statistical functionality from Julia and this is perfect. One issue I have encountered follows (in Julia):
using RCall
y = randn(10)
globalEnv[:y] = y
rcopy("typeof(y)")
returns "complex". One can easily get around this by inserting the additional line:
reval("y <- Re(y)")
But I thought I would raise it as an issue here just in case there are situations where this work-around will fail.
Cheers.
In order to get features like graphics windows working correctly, we need to be able to interact with the R event loops. Some details are covered in R-ext ยง8.
From what I understand, we need to implement (some of) the functionality provided by run_Rmainloop
.
It would be useful if we could automatically install R when no local installation is found. Here are some thoughts from having spent a morning trying and failing to get this to work:
The most promising option seems to be to use Conda.jl (which is what PyCall.jl uses). However:
R.dll
/libR.dylib
/libR.so
) is not located in a findable directory.Getting this to work is probably going to require changing the conda recipe.
deps/build.jl should create the name of libR
but that is not what is recorded in the deps/deps.jl file.
Hi,
Thank you for developing the package.
I have installรจd RCall v0.3.1, on Windows 10. I am using Julia ver.0.4.1.
Pkg.add("RCall")
using DataArrays,DataFrames,RCall
attenu = DataFrame(:attenu)
which gives error:
oadError: MethodError: `convert` has no method matching convert(::Type{DataFrames.DataFrame}, ::Symbol)
This may have arisen from a call to the constructor DataFrames.DataFrame(...),
since type constructors fall back to convert methods.
Closest candidates are:
call{T}(::Type{T}, ::Any)
convert(::Type{DataFrames.DataFrame}, !Matched::Array{T,2})
convert(::Type{DataFrames.DataFrame}, !Matched::Dict{K,V})
...
while loading In[4], in expression starting on line 1
in call at essentials.jl:56
However,when I typed rprint(:airmiles)
then the command works, ang gives the answer
Time Series:
Start = 1937
End = 1960
Frequency = 1
[1] 412 480 683 1052 1385 1418 1634 2178 3362 5948 6109 5981
[13] 6753 8003 10566 12528 14760 16769 19819 22362 25340 25343 29269 30514
Thank you for your kind help.
It might be nice to be able to call R code via a macro string literal, similar to this proposal: JuliaInterop/MATLAB.jl#29.
Of course, one problem would be that using $
for variable substitution would conflict with R lookup usage.
I can't convert a Julia Matrix{Float64} into sexp:
feldt:~/.julia/v0.3$ julia
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "help()" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.3.5 (2015-01-08 22:33 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-apple-darwin13.4.0
julia> using RCall
julia> m = [0.0 1.0; 2.0 3.0]
2x2 Array{Float64,2}:
0.0 1.0
2.0 3.0
julia> rm = sexp(m)
ERROR: l not defined
in sexp at /Users/feldt/.julia/v0.3/RCall/src/sexp.jl:129
Seems to me that l should instead be q (or p?) on line 129.
While working against the current master for RCall (obtained via Pkg.checkout("RCall")
), when executing:
using RCall
from within a either a 32-bit or a 64-bit Julia session on Windows, the value assigned to Pkg.dir()
is currently being modified.
This behavior creates problems when attempting to load other packages later in the same Julia session.
Below is an example Julia session:
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.4.0-pre+7067 (2015-08-28 17:05 UTC)
_/ |\__'_|_|_|\__'_| | Commit e82ba0c (11 days old master)
|__/ | i686-w64-mingw32
julia> Pkg.dir()
"C:\\Users\\Administrator\\.julia\\v0.4"
julia> using RCall
julia> Pkg.dir()
"C:\\Users\\Administrator\\Documents\\.julia\\v0.4"
julia>
Is there any reason for not turning on the travis ci testing service? It would be very helpful in checking if a PR is valid.
Reproduction below - is this an RCall or Julia issue ?
julia> using RCall
julia> @time for( i in 1:1000 ) rcopy( string("c(", join( [rand() * j for j in 1:1000], "," ), ")")) end
1.414018 seconds (6.17 M allocations: 285.378 MB, 2.55% gc time)
julia> @time for( i in 1:1000 ) rcopy( string("c(", join( [rand() * j for j in 1:1000], "," ), ")")) end
1.300732 seconds (6.05 M allocations: 280.270 MB, 2.04% gc time)
julia> @time for( i in 1:1000 ) rcopy( string("c(", join( [rand() * j for j in 1:1000], "," ), ")")) end
*** stack smashing detected ***: julia terminated
signal (6): Aborted
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f8e142e8394)
__fortify_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
__fortify_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f8c00b22641)
unknown function (ip: (nil))
Aborted (core dumped)
I have the latest version of R installed via Homebew (homebrew/science/r-3.2.3).
I am on OSX 10.11.1
I manually set ENV["R_HOME"] = "/usr/local/Cellar/r/3.2.3/"
When I call Pkg.build("RCall")
I get the following error
LoadError: Unable to locate libR.dylib
Try setting R_HOME, and re-run Pkg.build("RCall").
while loading /Users/rodonn/.julia/v0.4/RCall/deps/build.jl, in expression starting on line 3
I tried adding
ENV["DYLD_LIBRARY_PATH"] = "/usr/local/Cellar/r/3.2.3/lib"
ENV["LD_LIBRARY_PATH"] = "/usr/local/Cellar/r/3.2.3/lib"
but I still get the same error.
Thanks!
@simonbyrne
I notice that when I subset a StrSxp object with multiple indexes, it returns a julia array of CharSxp's. I think most users (at least myself) is expecting a StrSxp object with the corresponding indexes.
Is there any reasons for this implementation?
julia> a = RObject(["a", "b", "c"])
RCall.RObject{RCall.StrSxp}
[1] "a" "b" "c"
julia> a[1:2]
2-element Array{Any,1}:
RCall.RObject{RCall.CharSxp}
<CHARSXP: "a">
RCall.RObject{RCall.CharSxp}
<CHARSXP: "b">
Also, when only one element is being extracted from the StrSxp, the element of type CharSxp is returned to the user
julia> a[1]
RCall.RObject{RCall.CharSxp}
<CHARSXP: "a">
To mirror the R behavior, should it be wrapped inside a StrSxp object and then returned to the user? This may be less important.
Currently there is a mismatch of the way that R codes NA
's in a factor (index of R_NaInt
) and the way they are encoded in the DataArray package (index of 0). Should be easy to fix. This is just in case I forget.
The following code:
using RCall
d = Dict(1=>2, 2=> 3)
RObject(d)
errors out with:
ERROR: UndefVarError: allocVector not defined
in sexp at /Users/ranjan/.julia/v0.4/RCall/src/convert-base.jl:212
in call at /Users/ranjan/.julia/v0.4/RCall/src/types.jl:270
Could you please point me to where allocVector
is meant to be defined?
Looks like it is shaping up to be a great package. Thanks for spearheading this.
Are there plans for a more julian like higher level API maybe using macros?
Okay, another weird graphics bug. Certain unrelated julia functions will trigger the following error when an R graphics function is subsequently called
Error in plot.new() : the base graphics system is not registered
The following reliably triggers it on the second invocation of plot(1:10)
on my system (OS X, v0.3.7) when run at the REPL (though seems fine when in a script, or via include
).
using RCall
rprint("png('/tmp/aa.png')")
rprint("plot(1:10)")
rprint("dev.off()")
io = IOBuffer()
write(io,"1,2,3")
seek(io,0)
readall(io) # this seems to be the trigger
rprint("png('/tmp/aa.png')")
rprint("plot(1:10)")
rprint("dev.off()")
julia> Pkg.rm("RCall")
INFO: Removing RCall v0.2.1
INFO: Package database updated
julia> Pkg.add("RCall")
INFO: Installing RCall v0.2.1
INFO: Building RCall
INFO: Package database updated
julia> quit()
et-imac-retina:vams sjbespa$ julia
_
_ _ ()_ | A fresh approach to technical computing
() | () () | Documentation: http://docs.julialang.org
_ _ | | __ _ | Type "?help" for help.
| | | | | | |/ ` | |
| | || | | | (| | | Version 0.4.0-dev+6916 (2015-08-23 18:41 UTC)
/ |_'|||__'| | Commit f8c1986* (1 day old master)
|__/ | x86_64-apple-darwin14.5.0
julia> using RCall
ERROR: LoadError: LoadError: Timer(f) is deprecated. Use Timer(f, delay, repeat) instead.
in call at deprecated.jl:523
in include at ./boot.jl:259
in include_from_node1 at ./loading.jl:267
in include at ./boot.jl:259
in include_from_node1 at ./loading.jl:267
in require at ./loading.jl:206
while loading /Users/sjbespa/.julia/v0.4/RCall/src/eventloop.jl, in expression starting on line 16
while loading /Users/sjbespa/.julia/v0.4/RCall/src/RCall.jl, in expression starting on line 77
[For the record]
Finally, I have added the readthedocs support which generates documentation files semi-automatically.
Lexicon is used to extract the function's docstrings and generate the markdowns. See the build script under the docs directory. Running it will generate the markdown files. For example,
julia docs/build.jl
To push the files to readthedocs: right now, we have to trigger the build manually in readthedocs website. When this thing gets more mature, we should turn on the webhook.
julia> DataArray(reval("c(NA,1)"))
2-element DataArray{Float64,1}:
NaN
1.0
the correct result should be similar to
julia> @data([NA,1.0])
2-element DataArray{Float64,1}:
NA
1.0
Error is reported when converting a vector of string containing NA.
julia> DataArray(reval("c(NA,'a')"))
ERROR: `bytestring` has no method matching bytestring(::CharSxp)
in isNA at /Users/Randy/.julia/v0.3/RCall/src/sexp.jl:148
in DataArray at /Users/Randy/.julia/v0.3/RCall/src/sexp.jl:150
I'm not sure if the problem is with RCall
or with using LLMV 3.7.0 but trying to load the RCall package results in
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.4.0-rc2+31 (2015-09-23 01:56 UTC)
_/ |\__'_|_|_|\__'_| | Commit 09f248f* (2 days old release-0.4)
|__/ | x86_64-linux-gnu
julia> using DataFrames,DataArrays
julia> using RCall
julia: codegen.cpp:2999: llvm::Value* emit_assignment(llvm::Value*, jl_value_t*, jl_value_t*, bool, bool, jl_codectx_t*): Assertion `rval->getType() == jl_pvalue_llvmt || rval->getType() == NoopType' failed.
signal (6): Aborted
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f2a0b7e303d)
unknown function (ip: 0x7f2a0b7e30f2)
emit_assignment at /home/bates/git/julia/src/codegen.cpp:2999
emit_assignment at /home/bates/git/julia/src/codegen.cpp:3027
emit_function at /home/bates/git/julia/src/codegen.cpp:4681
to_function at /home/bates/git/julia/src/codegen.cpp:639
jl_compile at /home/bates/git/julia/src/codegen.cpp:808
jl_trampoline_compile_function at /home/bates/git/julia/src/builtins.c:1015
jl_apply_generic at /home/bates/git/julia/src/gf.c:1709
__init__ at /home/bates/.julia/v0.4/RCall/src/RCall.jl:117
unknown function (ip: 0x7f27f5c5f02d)
jl_eh_restore_state at /home/bates/git/julia/src/julia.h:1409
jl_eval_module_expr at /home/bates/git/julia/src/toplevel.c:210
jl_toplevel_eval_flex at /home/bates/git/julia/src/toplevel.c:423
jl_toplevel_eval_flex at /home/bates/git/julia/src/toplevel.c:573
jl_load at /home/bates/git/julia/src/toplevel.c:620
include at ./boot.jl:261
jl_apply_generic at /home/bates/git/julia/src/gf.c:1684
include_from_node1 at ./loading.jl:304
jl_apply_generic at /home/bates/git/julia/src/gf.c:1684
do_call at /home/bates/git/julia/src/interpreter.c:66
eval at /home/bates/git/julia/src/interpreter.c:213
jl_toplevel_eval_flex at /home/bates/git/julia/src/toplevel.c:544
jl_eh_restore_state at /home/bates/git/julia/src/julia.h:1409
require at ./loading.jl:243
unknown function (ip: 0x7f2a06660d39)
jl_apply_generic at /home/bates/git/julia/src/gf.c:1684
eval_import_path_ at /home/bates/git/julia/src/toplevel.c:368
jl_toplevel_eval_flex at /home/bates/git/julia/src/toplevel.c:442
jl_eh_restore_state at /home/bates/git/julia/src/julia.h:1409
eval_user_input at ./REPL.jl:63
Aborted (core dumped)
My versioninfo is
julia> versioninfo()
Julia Version 0.4.0-rc2+31
Commit 09f248f* (2015-09-23 01:56 UTC)
Platform Info:
System: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz
WORD_SIZE: 64
BLAS: libopenblas (NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: liblapack
LIBM: libopenlibm
LLVM: libLLVM-3.7.0
Is anyone else encountering this?
sexp("q")
SEXP{16}(Ptr{Void} @0x000000000ea8f988)
sexp(["p", "q"])
ERROR: `sexp` has no method matching sexp(::Array{ASCIIString,1})
Would be helpful to convert string vectors as well. Here is an example of my attempts to convert DataFrame to R object where this limitation shows up, as a part of this discussion.
PS: Thanks for the very helpful package!
I am trying to get RCall working for Win8/x64. I am working with the latest 0.3.7/x64 version of Julia for Windows. I first manually added the required environment variables as follows-
R_DOC_DIR = C:/PROGRA1/R/R-321.0/doc [Full path: C:\Program Files\R\R-3.2.0\doc]
R_HOME = C:/PROGRA1/R/R-321.0 [Full path: C:\Program Files\R\R-3.2.0]
R_INCLUDE_DIR = C:/PROGRA1/R/R-321.0/include [Full path: C:\Program Files\R\R-3.2.0\include]
R_SHARE_DIR = C:/PROGRA1/R/R-321.0/share [Full path: C:\Program Files\R\R-3.2.0\share]
LD_LIBRARY_PATH = C:/PROGRA1/R/R-321.0/modules/x64 [Full path: C:\Program Files\R\R-3.2.0\modules\x64]
In going through deps/build.jl, I noticed that it was trying to access [joinpath(ENV["R_HOME"],"lib",string("libR.",BinDeps.shlib_ext))] which expands to [ C:/PROGRA1/R/R-321.0/lib/libR.dll] but this file does not exist on Windows install of R. So I created this "lib" in C:/PROGRA1/R/R-321.0 and placed the dll "R.dll" from [C:\Program Files\R\R-3.2.0\bin\x64] in the lib directory. I renamed R.dll to libR.dll. This did not help. I get the error message
-- QUOTE --
================================[ ERROR: RCall ]================================
Unable to load C:/PROGRA1/R/R-321.0/lib/libR.dll
Please re-run Pkg.build(package), and restart Julia.
while loading C:\Users\Krishna.julia\v0.3\RCall\deps\build.jl, in expression st
arting on line 14
-- UNQUOTE --
Just for good measure, I copied over all the other dlls found in C:\Program Files\R\R-3.2.0\bin\x64 over to the "lib" folder but that did not help either.
If anyone has got a working Windows version of Rcall working, kindly share your setup.
Thanks.
@simonbyrne
Thanks for the IJulia hooks. The implementation makes RCall.jl more usable.
I see that Julia objects are now implicitly converted to Sexp objects. And we are seeing crazy axis labels (in graphics.ipynb) because there are no R labels associating the numbers. All the numbers are directly passed to the plot function without masking them with a label.
> X = linspace(0,pi,10)
> rprint(RCall.lang(:plot, sexp(X), sexp(sin(X))))
plot(c(0, 0.349065850398866, 0.698131700797732, 1.0471975511966,
1.39626340159546, 1.74532925199433, 2.0943951023932, 2.44346095279206,
2.79252680319093, 3.14159265358979), c(0, 0.342020143325669,
0.642787609686539, 0.866025403784439, 0.984807753012208, 0.984807753012208,
0.866025403784439, 0.642787609686539, 0.342020143325669, 1.22464679914735e-16
))
To avoid this, we could pass the Julia objects to R and then plot
with the R objects.
X = linspace(0,pi,10)
globalEnv[:X] = X
globalEnv[:Y] = sin(X)
rcall(:plot, :X, :Y)
Actually, I am thinking of another way to convert Julia objects. For example, for each rcall
call, we create a new environment via new.env()
, if an argument is not a Sexp, we convert it to an R object and stored it in the new environment. Perhaps something like
X = linspace(0,pi,10)
E = rcall(symbol("new.env"))
E[:X] = X
E[:Y] = sin(X)
rcall(:plot, :X, :Y, env=E)
PS: in graphics.jl, rprint
is used to "print" the rcall
. Actually, it is not necessary.
I open a new notebook, first cell is
using RCall
Second cell is
"x <- 5" |> rcopy
This returns an empty graph as the first output, and only then the real output of
1-element Array{Float64,1}:
5.0
If I then add a third cell that has purely julia code, it will also add this empty graph in the out cell.
I attach a screen shot:
I'm on Windows, julia 0.3.11, IPython/Jupyter 3 and all packages updated to the latest version. This happends with RCall from master or the latest registered version.
Any idea?
If I was to call R's stars function. It is easy to invoke it with
rprint(rcall(:stars,myDf))
However if I try to set the draw.segments=TRUE
as I would in R
. The following invocation fails
rprint(rcall(:stars,myDf,draw.segments=true))
ERROR: syntax: keyword argument is not a symbol: "draw.segments"
I saw nothing in the documentation to clarify how this might be handled.
They call lang3 instead of lang4/lang5/lang6 which means that later args (> 3) are not "seen" by R.
./deps.jl
should be rebuilt when R is updated, or wrong dylib will be loaded.
https://github.com/randy3k/RCall.jl/blob/8f1f2144b91f146c659009b7364182b40c304f7e/deps/build.jl#L26
Hi @dmbates,
With the recent PackageEvaluator rework I think its not only reasonable but possible to support R-based packages like RCall.
Currently RCall is failing its tests:
http://pkg.julialang.org/?pkg=RCall&ver=release
I am installing R:
https://github.com/IainNZ/PackageEvaluator.jl/blob/1428070377795d2b3977e8f768633f862d0c6138/scripts/setup.sh#L71-L72
But I'm wondering if maybe its too old a version?
When I run RCall in Julia 0.4.0, it have such problem. I tried Pkg.build("RCall") but it not solved. Previously RCall worked fine but the problem came after I updated anaconda (I have no idea why anaconda will lead this problem, maybe it is just coincident?).
julia> using RCall
ERROR: LoadError: InitError: cglobal: could not find symbol R_BlankScalarString in li
brary /usr/lib64/R/lib/libR.so
in init at /home/jxiong/.julia/v0.4/RCall/src/RCall.jl:71
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
during initialization of module RCall
while loading /home/jxiong/.julia/v0.4/RCall/src/RCall.jl, in expression starting on
line 53
Hello,
I'm getting "Unable to load the LibR.dll" when trying to add and build RCall.
I have set the R exe and RScript in my windows path.
Any help would be appreciated.
Thanks
Julia version 3.5 64 bit for windows
I had been wondering for some time how a string modifier like the 'r
' in r"my\w+regexp"
was defined and whether we could define R"x <- seq(0,1,101)"
to mean reval("x <- seq(0,1,101)")
, say. It turns out that the magic is defining a macro with the name R_str
.
Does it seem worthwhile allowing this kind of simplification of calls to reval(str)
or, perhaps, rcopy(reval(str))
. I find that when using the RCall
package I get tired of writing that sequence of calls over and over.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.