Skip to content

Commit 8e67eb1

Browse files
committed
First commit
0 parents  commit 8e67eb1

16 files changed

+685
-0
lines changed

.RData

67 Bytes
Binary file not shown.

.Rhistory

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
require(jl4R)
2+
.jlBegin()
3+
q()
4+
require(jl4R)
5+
.jlBegin()
6+
.jlRunning()
7+
q()
8+
require(jl4R)
9+
.jlRunning()
10+
.jlBegin()
11+
.jl("a=1")
12+
.jl("a=[1]")
13+
.jl('a=["1"]')
14+
q()
15+
require(jl4R)
16+
.jlBegin()
17+
.jl('a=["1"]')
18+
.jl('a=["1",1]')
19+
q()
20+
require(jl4R)
21+
.jlBegin()
22+
.jl('a=["1",1]')
23+
.jl('a=[2,1]')
24+
q()
25+
require(jl4R)
26+
.jlBegin()
27+
.jl('a=[2,1]')
28+
list(1,2,3)
29+
as.vector(list(1,2,3))
30+
unlist(list(1,2,3))
31+
unlist(list(1,"2",3))
32+
sapply(list(1,"2",3),is.integer)
33+
is.integer(list(1,"2",3))
34+
sapply(list(1,"2",3),is.integer)
35+
sapply(list(1,"2",3),is.numeric)
36+
all(sapply(list(1,"2",3),is.numeric))
37+
all.equal(sapply(list(1,"2",3),class)
38+
)
39+
all.equal(sapply(list(1,"2",3),class))
40+
q()
41+
require(jl4R)
42+
.jlBegin()
43+
.jl('a=[2,1]')
44+
q()
45+
require(jl4R)
46+
.jlBegin()
47+
.jl('a=[2,1]')
48+
q()
49+
require(jl4R)
50+
.jlBegin()
51+
.jl('a=[2,1]')
52+
q()
53+
require(jl4R)
54+
.jlBegin()
55+
.jl('a=[2,1]')
56+
q()
57+
require(jl4R)
58+
.jlBegin()
59+
.jl('a=[2,1]')
60+
.jl('a=[2,"1"]')
61+
.jl('a=["2","1"]')
62+
q()
63+
require(jl4R)
64+
.jlBegin()
65+
.jl('a=["2","1"]')
66+
q()
67+
require(jl4R)
68+
.jlBegin()
69+
.jl('a=["2","1"]')
70+
q()
71+
require(jl4R)
72+
.jlBegin()
73+
.jl('a=["2","1"]')
74+
q()
75+
require(jl4R)
76+
.jlBegin()
77+
.jl('a=[2,1]')
78+
.jl('a=[2.,1.]')
79+
q()
80+
require(jl4R)
81+
.jlBegin()
82+
.jl('a=[2.,1.]')
83+
.jl('a=[2.,1.]') -> a
84+
a
85+
is.integer(a)
86+
is.double(a)
87+
is.real(a)
88+
q()
89+
require(jl4R)
90+
.jlBegin()
91+
.jl('a=["2","1"]')
92+
q()
93+
require(jl4R)
94+
.jlBegin()
95+
.jl('a=[2im,1im]')
96+
.jl('a=[2.im,1.im]')
97+
.jl('a=[1+2.im,1.im]')
98+
q()
99+
require(jl4R)
100+
.jlBegin()
101+
.jl('a=[1+2.im,1.im]')
102+
.jl('a=[1+2im,1im]')
103+
.jl('a=[1+2im,1im]') -> a
104+
im(a)
105+
imag(a)
106+
im(a)
107+
re(a)
108+
class(a)
109+
methods(complex)
110+
a.im
111+
a$im
112+
Im(a)
113+
is.integer(Im(a))
114+
is.numeric(Im(a))
115+
q()
116+
require(jl4R)
117+
.jlBegin()
118+
.jl('a=1+2im')
119+
require(jl4R)
120+
.jlBegin()
121+
.jl('a=1+2im')
122+
.jl('a=1+2.im')
123+
.jl('a')
124+
.jl('"a"')
125+
.jl('a="a"')
126+
.jl('a=typeof("a")')
127+
.jl('a=typeof("â")')
128+
.jl('a="â"')
129+
.jl('using RDatasets')
130+
.jl('iris=data("datasets","iris"')
131+
.jl('iris=data("datasets","iris")')
132+
.jl('iris')
133+
q()
134+
require(jl4R)
135+
.jlBegin()
136+
.jl('using RDatasets')
137+
.jl('iris=data("datasets","iris")')
138+
.jl('vector(iris[1])')
139+
q()
140+
require(jl4R)
141+
.jl('vector(iris[1])')
142+
.jl('[1,"2"]')
143+
.jl('[1,"2",TRUE]')
144+
.jl('[TRUE]')
145+
.jl('TRUE')
146+
q()
147+
require(jl4R)
148+
.jl('TRUE')
149+
.jl('[TRUE]')
150+
q()
151+
require(jl4R)
152+
.jl('[TRUE]')
153+
q()
154+
require(jl4R)
155+
.jl('[TRUE]')
156+
.jl('true')
157+
.jl('false')
158+
.jl('[false]')
159+
.jl('[false,true]')
160+
.jl('[false,1]')
161+
.jl('[1.,1]')
162+
q()

DESCRIPTION

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Package: jl4R
2+
Version: 0.0.1
3+
Title: Julia Interface
4+
Author: Cqls Team
5+
Maintainer: Remy Drouilhet <[email protected]>
6+
Description: Interface to julia
7+
License: GPL Version 2 or later.
8+
Archs: x86_64

INDEX

Whitespace-only changes.

NAMESPACE

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
useDynLib(jl4R, .registration = TRUE)
2+
3+
exportPattern("^\\.jl")
4+
export(
5+
6+
#jlObj
7+
8+
)
9+
10+
#S3methods are not viewable inside the R system. If you want this functionality available put it in the previous export
11+
12+

R/jl4R.R

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## the main ruby parsing expression !!!
2+
.jl <- function(...) {
3+
if(!.jlRunning()) .jlInit()
4+
.External("jl4R_eval", ..., PACKAGE = "jl4R")
5+
}
6+
7+
8+
.jlInit<-function(imgdir=file.path(Sys.getenv("JLAPI_HOME"),"lib")) {
9+
.External("jl4R_init",imgdir ,PACKAGE="jl4R")
10+
return(invisible())
11+
}
12+
13+
.jlRunning <- function() {
14+
.Call("jl4R_running", PACKAGE = "jl4R")
15+
}

R/unix/zzz.R

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.First.lib <- function(lib, pkg) {
2+
## Use local=FALSE to allow easy loading of Tcl extensions
3+
library.dynam("jl4R", pkg, lib)#,local=FALSE)
4+
}

R/unix/zzz.Rstub

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.First.lib <- function(lib, pkg)
2+
stop("Ruby support is not available on this system")

R/windows/zzz.R

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.First.lib <- function(lib, pkg) {
2+
## Use local=FALSE to allow easy loading of Tcl extensions
3+
library.dynam("jl4R", pkg, lib,local=FALSE)
4+
5+
}

README.md

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.

src/Makevars

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PKG_CFLAGS = -I${JLAPI_HOME}/include/julia -I.
2+
PKG_LIBS = -L${JLAPI_HOME}/lib/julia -Wl,-rpath,${JLAPI_HOME}/lib/julia -ljulia-release

src/htableh.inc

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//-*- mode:c -*-
2+
3+
#include "htable.h"
4+
5+
#define HTPROT(HTNAME) \
6+
void *HTNAME##_get(htable_t *h, void *key); \
7+
void HTNAME##_put(htable_t *h, void *key, void *val); \
8+
void HTNAME##_adjoin(htable_t *h, void *key, void *val); \
9+
int HTNAME##_has(htable_t *h, void *key); \
10+
int HTNAME##_remove(htable_t *h, void *key); \
11+
void **HTNAME##_bp(htable_t *h, void *key);
12+
13+
// return value, or HT_NOTFOUND if key not found
14+
15+
// add key/value binding
16+
17+
// add binding iff key is unbound
18+
19+
// does key exist?
20+
21+
// logically remove key
22+
23+
// get a pointer to the location of the value for the given key.
24+
// creates the location if it doesn't exist. only returns NULL
25+
// if memory allocation fails.
26+
// this should be used for updates, for example:
27+
// void **bp = ptrhash_bp(h, key);
28+
// *bp = f(*bp);
29+
// do not reuse bp if there might be intervening calls to ptrhash_put,
30+
// ptrhash_bp, ptrhash_reset, or ptrhash_free.

0 commit comments

Comments
 (0)