|
| 1 | +# Julia for R |
| 2 | + |
| 3 | +This is an attempt to embed the julia language in R. Actually, very basic julia types are converted to R objects (DataFrame coming soon!). |
| 4 | + |
| 5 | + |
| 6 | +## Install |
| 7 | + |
| 8 | +Clone this git and in the parent directory: |
| 9 | + |
| 10 | + R CMD INSTALL jl4R |
| 11 | + |
| 12 | +## Test |
| 13 | + |
| 14 | +First, in a terminal or in your .bashrc (or equivalent): |
| 15 | + |
| 16 | + export JLAPI_HOME=<your julia home> |
| 17 | + |
| 18 | +Then, the R console: |
| 19 | + |
| 20 | +```{.R execute="false"} |
| 21 | +require(jl4R) # => true |
| 22 | +.jl('LOAD_PATH') # => [<your julia home>/local/share/julia/site/v0.2", "<your julia home>/share/julia/site/v0.2"] |
| 23 | +``` |
| 24 | + |
| 25 | +If the last result is unexpected, see the Troubles section. |
| 26 | + |
| 27 | +## Example |
| 28 | +```{.R execute="false"} |
| 29 | +require(jl4R) |
| 30 | +# .jlInit() since automatically called once |
| 31 | +.jl('using RDatasets') # A bit slow, julia and RDatasets initializations |
| 32 | +a<-.jl('iris=data("datasets","iris")') |
| 33 | +.jl(vector(iris[2])) |
| 34 | + |
| 35 | +# a is then an R object |
| 36 | +a |
| 37 | + |
| 38 | +# another call |
| 39 | +.jl('colnames(iris)') |
| 40 | + |
| 41 | +# a plot should work too! |
| 42 | +plot(.jl('vector(iris[1])')~.jl('vector(iris[2])')) |
| 43 | +``` |
| 44 | + |
| 45 | +## Troubles |
| 46 | + |
| 47 | +1. htableh.inc in src/support directory is missing (copy it in include/julia of your julia directory). *Update*: htableh.inc is now in the package (src/jl4R) until the julia core solve the problem. |
| 48 | + |
| 49 | +2. If (like me, on MacOSX) the result of the previous test is wrong, the reason may come from the fact that in the initialization of julia libpcre is required and failed to be loaded properly. Then, set |
| 50 | + |
| 51 | + |
| 52 | + LD_LIBRARY_PATH=<your julia home>/lib/julia |
| 53 | + |
| 54 | + |
| 55 | +If you don't want to set LD_LIBRARY_PATH, alternatives solutions would be: |
| 56 | + |
| 57 | +* Solution 1 (maybe the best): |
| 58 | + |
| 59 | +change the base/client.jl file as follows: |
| 60 | + |
| 61 | +split init_load_path into 2 functions |
| 62 | + |
| 63 | +```{.julia execute="false"} |
| 64 | + function init_load_path() |
| 65 | + vers = "v$(VERSION.major).$(VERSION.minor)" |
| 66 | + |
| 67 | + global const DL_LOAD_PATH = ByteString[ |
| 68 | + join([JULIA_HOME,"..","lib","julia"],Base.path_separator) |
| 69 | + ] |
| 70 | + |
| 71 | + global const LOAD_PATH = ByteString[ |
| 72 | + abspath(JULIA_HOME,"..","local","share","julia","site",vers), |
| 73 | + abspath(JULIA_HOME,"..","share","julia","site",vers) |
| 74 | + ] |
| 75 | + end |
| 76 | +``` |
| 77 | + |
| 78 | +Notice that abspath is not used in the definition of DL_LOAD_PATH (since libpcre is required by abspath which depends of DL_LOAD_PATH needed by dlopen). |
| 79 | +Of course, DL_LOAD_PATH depends on the definition of JULIA_HOME (supposed to be here: "your julia home"/lib) which normally is related to |
| 80 | +the location of sys.ji. In such a case, you can install the R package. |
| 81 | + |
| 82 | +3. For linux user, you should also put jl_bytestring_ptr in julia.expmap. |
0 commit comments