R4rb 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/R4rb.gemspec +32 -0
- data/Rakefile +114 -0
- data/ext/R4rb/MANIFEST +0 -0
- data/ext/R4rb/R4rb.c +595 -0
- data/ext/R4rb/extconf.rb +133 -0
- data/lib/R2rb.rb +5 -0
- data/lib/R4rb.rb +59 -0
- data/lib/R4rb/R2rb_eval.rb +116 -0
- data/lib/R4rb/R2rb_init.rb +109 -0
- data/lib/R4rb/R4rb.rb +164 -0
- data/lib/R4rb/Rserve.rb +208 -0
- data/lib/R4rb/converter.rb +69 -0
- data/lib/R4rb/init.rb +127 -0
- data/lib/R4rb/robj.rb +46 -0
- data/lib/Rserve.rb +8 -0
- data/script/README +5 -0
- data/script/Rserv +39 -0
- data/script/install_Rserv +8 -0
- data/test/R4rbRserve.rb +30 -0
- data/test/compR4rbRserve.rb +2 -0
- data/test/test.rb +89 -0
- data/test/testArray.rb +27 -0
- data/test/testBuffer.rb +12 -0
- data/test/testConsole.rb +5 -0
- data/test/testR4rb.rb +42 -0
- data/test/testRVect.rb +18 -0
- data/test/testRserve.rb +90 -0
- data/test/test_error.rb +32 -0
- metadata +74 -0
data/lib/Rserve.rb
ADDED
data/script/README
ADDED
data/script/Rserv
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
## Rmk: IMPORTANT, $0 does not have the same name as the binary Rserve!!!
|
3
|
+
|
4
|
+
pid=`pgrep -x Rserve` #`ps -C Rserve -o pid=`
|
5
|
+
|
6
|
+
#echo "<<$pid>>"
|
7
|
+
|
8
|
+
|
9
|
+
rservePath=`Rscript -e "cat(system.file(\"libs\",version[[\"arch\"]],\"Rserve\",package=\"Rserve\"))"`
|
10
|
+
|
11
|
+
if [ "$rservePath" == "" ]; then
|
12
|
+
rservePath=`Rscript -e "cat(system.file(\"Rserve\",package=\"Rserve\"))"`
|
13
|
+
fi
|
14
|
+
|
15
|
+
case $1 in
|
16
|
+
status)
|
17
|
+
if [ "$pid" = "" ]; then
|
18
|
+
echo "Rserv is NOT running!"
|
19
|
+
else
|
20
|
+
echo "Rserv is running!"
|
21
|
+
fi
|
22
|
+
;;
|
23
|
+
start)
|
24
|
+
if [ "$pid" = "" ]; then
|
25
|
+
R CMD $rservePath
|
26
|
+
##echo "Rserv started!"
|
27
|
+
else
|
28
|
+
echo "Rserv already started!"
|
29
|
+
fi
|
30
|
+
;;
|
31
|
+
stop)
|
32
|
+
if [ "$pid" = "" ]; then
|
33
|
+
echo "Rserv already stopped!"
|
34
|
+
else
|
35
|
+
kill $pid
|
36
|
+
echo "Rserv stopped!"
|
37
|
+
fi
|
38
|
+
;;
|
39
|
+
esac
|
data/test/R4rbRserve.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Test
|
2
|
+
def test
|
3
|
+
"test1: #{self}"
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module Test2
|
8
|
+
def test
|
9
|
+
"test2: #{self}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
#Test2=Test unless Module.constants.include? "Test2"
|
14
|
+
|
15
|
+
#def update_class(test)
|
16
|
+
|
17
|
+
class String
|
18
|
+
|
19
|
+
include Test
|
20
|
+
|
21
|
+
def String.modeR=(rmode)
|
22
|
+
load_module(Test) if rmode==1
|
23
|
+
load_module(Test2) if rmode==2
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_R
|
27
|
+
self.test
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require "R4rb"
|
2
|
+
|
3
|
+
R4rb.init
|
4
|
+
|
5
|
+
### without argument the default mode is R2rb
|
6
|
+
### with 1 arguments, it is updated to Rserve
|
7
|
+
### with 2 arguments, it is then updated to R2rb
|
8
|
+
|
9
|
+
if ARGV.length==1
|
10
|
+
R4rb_is Rserve
|
11
|
+
Rserve.init
|
12
|
+
Rserve.client(:toto)
|
13
|
+
end
|
14
|
+
|
15
|
+
if ARGV.length==2
|
16
|
+
R4rb_is R2rb
|
17
|
+
end
|
18
|
+
|
19
|
+
R4rb.eval <<-CodeR
|
20
|
+
require(ctest)
|
21
|
+
a<-c(1.1+2i,2)
|
22
|
+
print('titi')
|
23
|
+
print('tata')
|
24
|
+
b<-rnorm(10)
|
25
|
+
a=as.integer(c(1,2,1,4))
|
26
|
+
print(mode(a))
|
27
|
+
e<-list(a=c(1,3,2))
|
28
|
+
# bug!!!
|
29
|
+
for(i in 1:10) {
|
30
|
+
print(i)
|
31
|
+
}
|
32
|
+
CodeR
|
33
|
+
|
34
|
+
rvect=R4rb::RVector.new "a"
|
35
|
+
p rvect
|
36
|
+
## the 3 are aliases!
|
37
|
+
p rvect.get
|
38
|
+
p rvect.value
|
39
|
+
p rvect.value.to_a
|
40
|
+
## extract the first element
|
41
|
+
p rvect[0]
|
42
|
+
## connection between a ruby Array and an R vector! In fact the ruby Array is a cache!
|
43
|
+
## No more creation of ruby Array is necessary!
|
44
|
+
a=[]
|
45
|
+
rvect > a
|
46
|
+
puts "content of a (after 'rvect > a')";p a;p a.object_id
|
47
|
+
#print (rvect << "a").class,"\n"
|
48
|
+
rvect << "as.integer(e[[1]])" > a
|
49
|
+
puts "content of a (after 'rvect << \"e[[1]]\" > a')";p a;p a.object_id
|
50
|
+
print rvect.name,"=",a.inspect,"\n"
|
51
|
+
print "length(",rvect.name,")=",rvect.length,"\n"
|
52
|
+
print rvect.name,"[0] is of class ",a[0].class,"\n"
|
53
|
+
rvect << :b
|
54
|
+
print rvect.name,"=",rvect.get.inspect,"\n"
|
55
|
+
print "length(",rvect.name,")=",rvect.length,"\n"
|
56
|
+
rvect << :a #> a
|
57
|
+
print rvect.name,"=",rvect.to_a.inspect,"\n"
|
58
|
+
print "length(",rvect.name,")=",rvect.length,"\n"
|
59
|
+
print rvect.name,"[2]=",rvect[2],"\n"
|
60
|
+
#rvect.set [true,false,false]
|
61
|
+
rvect << "x<-seq(-3,3,l=10)" > a
|
62
|
+
p a
|
63
|
+
rvect << "dnorm(x)" > a
|
64
|
+
p a
|
65
|
+
rvect << "e$a"
|
66
|
+
rvect < [true,false,false]
|
67
|
+
# could be used with affectation symbol
|
68
|
+
p rvect.value
|
69
|
+
rvect.value = rvect.value + [true,false,true]
|
70
|
+
R4rb.eval <<-CodeR
|
71
|
+
print(e$a)
|
72
|
+
print(length(e$a))
|
73
|
+
CodeR
|
74
|
+
print rvect.name,"=",rvect.to_a.inspect,"\n"
|
75
|
+
print "length(",rvect.name,")=",rvect.length,"\n"
|
76
|
+
print rvect.name,"=",rvect.to_a.inspect,"\n"
|
77
|
+
print rvect.name,"[2]=",rvect[2],"\n"
|
78
|
+
|
79
|
+
#with argument (used in dyndoc and notably in parser)
|
80
|
+
rvect.arg="[2]"
|
81
|
+
print rvect.get_with_arg,"\n"
|
82
|
+
rvect << :e
|
83
|
+
rvect.arg="$a"
|
84
|
+
p rvect.get_with_arg
|
85
|
+
rvect.arg="$a[2]"
|
86
|
+
p rvect.get_with_arg
|
87
|
+
rvect.value_with_arg="toto"
|
88
|
+
rvect.arg="$a"
|
89
|
+
p rvect.value_with_arg
|
data/test/testArray.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'R4rb'
|
2
|
+
|
3
|
+
Array.initR
|
4
|
+
|
5
|
+
### without argument the default mode is R2rb
|
6
|
+
### with 1 arguments, it is updated to Rserve
|
7
|
+
### with 2 arguments, it is then updated to R2rb
|
8
|
+
|
9
|
+
if ARGV.length==1
|
10
|
+
R4rb_is Rserve
|
11
|
+
Rserve.init
|
12
|
+
Rserve.client(:toto)
|
13
|
+
puts "init cli";p Rserve.cli
|
14
|
+
end
|
15
|
+
|
16
|
+
if ARGV.length==2
|
17
|
+
R4rb_is R2rb
|
18
|
+
end
|
19
|
+
|
20
|
+
puts "calcul de runif(10)"
|
21
|
+
a=[] < 'runif(10)'
|
22
|
+
p a
|
23
|
+
a.map!{|e| e*2}
|
24
|
+
|
25
|
+
a > 'b'
|
26
|
+
|
27
|
+
p 'b'.to_R
|
data/test/testBuffer.rb
ADDED
data/test/testConsole.rb
ADDED
data/test/testR4rb.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'R4rb'
|
2
|
+
|
3
|
+
Array.initR
|
4
|
+
|
5
|
+
### without argument the default mode is R2rb
|
6
|
+
### with 1 arguments, it is updated to Rserve
|
7
|
+
### with 2 arguments, it is then updated to R2rb
|
8
|
+
|
9
|
+
if ARGV.length==1
|
10
|
+
R4rb_is Rserve
|
11
|
+
Rserve.init
|
12
|
+
Rserve.client(:toto)
|
13
|
+
puts "init cli";p Rserve.cli
|
14
|
+
end
|
15
|
+
|
16
|
+
if ARGV.length==2
|
17
|
+
R4rb_is R2rb
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
|
22
|
+
R4rb_status?
|
23
|
+
|
24
|
+
p R2rb.parse "rnorm(toto"
|
25
|
+
|
26
|
+
p R2rb.parse 'RSeval(toto,evalq({{
|
27
|
+
#Sys.sleep(10)
|
28
|
+
aaa2 <- "toto"
|
29
|
+
}},.GlobalEnv$.env4dyn$linuxR))'
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
$out=[]
|
34
|
+
p $out.object_id
|
35
|
+
|
36
|
+
p R4rb << "rnorm(10)"
|
37
|
+
|
38
|
+
p R4rb << ".output<<-capture.output({capabilities()\n\n})"
|
39
|
+
|
40
|
+
p ($out < '.output' )
|
41
|
+
|
42
|
+
#p ".output".to_R
|
data/test/testRVect.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'../lib/R4rb')
|
2
|
+
|
3
|
+
Array.initR
|
4
|
+
|
5
|
+
|
6
|
+
## Assignment from ruby to R
|
7
|
+
R4rb::RVector.assign("a",[1,2,3])
|
8
|
+
|
9
|
+
"print(a)".to_R
|
10
|
+
|
11
|
+
[1,4,3].to_R(:b) #R4rb::RVector.assign("b",[1,4,3])
|
12
|
+
|
13
|
+
"print(b)".R4rb #instead of to_R
|
14
|
+
|
15
|
+
## Assignment from R to ruby
|
16
|
+
a="3:1".evalR #instead of to_R
|
17
|
+
|
18
|
+
p a
|
data/test/testRserve.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'../lib/R4rb')
|
2
|
+
|
3
|
+
## The R server needs to be initialized first outside this test!
|
4
|
+
Rserve.client(:toto)
|
5
|
+
|
6
|
+
Rserve < "aaa<-1"
|
7
|
+
|
8
|
+
Rserve < "aaa"
|
9
|
+
|
10
|
+
"aaa".Rserve
|
11
|
+
|
12
|
+
Rserve.client(:titi)
|
13
|
+
|
14
|
+
Rserve < "b<-10"
|
15
|
+
|
16
|
+
"ls()".Rserve(:toto)
|
17
|
+
|
18
|
+
"ls()".Rserve(:titi)
|
19
|
+
|
20
|
+
p "ls()".R2rb
|
21
|
+
|
22
|
+
Rserve.output <<-CodeR
|
23
|
+
a<-c(1.1+2i,2)
|
24
|
+
print('titi')
|
25
|
+
print('tata')
|
26
|
+
b<-rnorm(10)
|
27
|
+
a=as.integer(c(1,2,1,4))
|
28
|
+
print(mode(a))
|
29
|
+
e<-list(a=c(1,3,2))
|
30
|
+
# bug!!!
|
31
|
+
for(i in 1:10) {
|
32
|
+
print(i)
|
33
|
+
}
|
34
|
+
CodeR
|
35
|
+
|
36
|
+
rvect=Rserve::RVector.new "a"
|
37
|
+
p rvect
|
38
|
+
"a".Rserve
|
39
|
+
## the 3 are aliases!
|
40
|
+
p rvect.get
|
41
|
+
p rvect.value
|
42
|
+
p rvect.to_a
|
43
|
+
## extract the first element
|
44
|
+
p rvect[0]
|
45
|
+
## connection between a ruby Array and an R vector! In fact the ruby Array is a cache!
|
46
|
+
## No more creation of ruby Array is necessary!
|
47
|
+
a=[]
|
48
|
+
rvect > a
|
49
|
+
puts "content of a (after 'rvect > a')";p a;p a.object_id
|
50
|
+
rvect << "e[[1]]" > a
|
51
|
+
puts "content of a (after 'rvect << \"e[[1]]\" > a')";p a;p a.object_id
|
52
|
+
|
53
|
+
rvect << "a"
|
54
|
+
rvect < [true,false,true]
|
55
|
+
|
56
|
+
p ".rubyExport".R2rb
|
57
|
+
|
58
|
+
Rserve.output <<-CodeR
|
59
|
+
print(a)
|
60
|
+
print(length(a))
|
61
|
+
CodeR
|
62
|
+
|
63
|
+
rvect.value = rvect.value + [true,false,true]
|
64
|
+
p ".rubyExport".to_R
|
65
|
+
|
66
|
+
Rserve.output <<-CodeR
|
67
|
+
print(a)
|
68
|
+
print(length(a))
|
69
|
+
CodeR
|
70
|
+
|
71
|
+
p "ls(all=T)".Rserve
|
72
|
+
|
73
|
+
rvect.arg="[2]"
|
74
|
+
print rvect.get_with_arg,"\n"
|
75
|
+
|
76
|
+
rvect << :e
|
77
|
+
rvect.arg="$a"
|
78
|
+
p rvect.get_with_arg
|
79
|
+
rvect.arg="$a[2]"
|
80
|
+
p rvect.get_with_arg
|
81
|
+
|
82
|
+
|
83
|
+
rvect.value_with_arg="toto"
|
84
|
+
"print(.rubyExport)".R2rb
|
85
|
+
rvect.arg="$a"
|
86
|
+
Rserve.output <<-CodeR
|
87
|
+
print(e)
|
88
|
+
print(e$a)
|
89
|
+
CodeR
|
90
|
+
p rvect.value_with_arg
|
data/test/test_error.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "R4rb"
|
2
|
+
|
3
|
+
R4rb.init
|
4
|
+
|
5
|
+
if ARGV.length==1
|
6
|
+
R4rb_is Rserve
|
7
|
+
Rserve.init
|
8
|
+
Rserve.client(:toto)
|
9
|
+
end
|
10
|
+
|
11
|
+
if ARGV.length==2
|
12
|
+
R4rb_is R2rb
|
13
|
+
end
|
14
|
+
|
15
|
+
R4rb.try_eval <<-CodeR
|
16
|
+
print(rnorm(10))
|
17
|
+
toto
|
18
|
+
CodeR
|
19
|
+
|
20
|
+
=begin
|
21
|
+
if R4rb==Rserve
|
22
|
+
## copy of code for obtaining the same resut as before
|
23
|
+
puts (R2rb.output "RSeval(toto,\"capture.output({.result_try_code<- try({print(rnorm(10))\ntoto},silent=TRUE)})\")").join("\n")
|
24
|
+
puts R2rb.output("RSeval(toto,\".result_try_code\")")
|
25
|
+
|
26
|
+
#Does not work! No print captured!
|
27
|
+
#puts (R2rb.output "RSeval(toto,\".result_try_code<- try({capture.output({print(rnorm(10))\ntoto})},silent=TRUE)\")")
|
28
|
+
#p R2rb.output("RSeval(toto,\".result_try_code\")")
|
29
|
+
end
|
30
|
+
=end
|
31
|
+
|
32
|
+
puts "ici"
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: R4rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CQLS
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |2
|
14
|
+
R is embedded in ruby with some communication support .
|
15
|
+
email: rdrouilh@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions:
|
18
|
+
- ext/R4rb/extconf.rb
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Rakefile
|
22
|
+
- R4rb.gemspec
|
23
|
+
- ext/R4rb/R4rb.c
|
24
|
+
- ext/R4rb/extconf.rb
|
25
|
+
- ext/R4rb/MANIFEST
|
26
|
+
- lib/R2rb.rb
|
27
|
+
- lib/R4rb.rb
|
28
|
+
- lib/R4rb/R2rb_eval.rb
|
29
|
+
- lib/R4rb/R2rb_init.rb
|
30
|
+
- lib/R4rb/R4rb.rb
|
31
|
+
- lib/R4rb/Rserve.rb
|
32
|
+
- lib/R4rb/converter.rb
|
33
|
+
- lib/R4rb/init.rb
|
34
|
+
- lib/R4rb/robj.rb
|
35
|
+
- lib/Rserve.rb
|
36
|
+
- test/R4rbRserve.rb
|
37
|
+
- test/compR4rbRserve.rb
|
38
|
+
- test/test.rb
|
39
|
+
- test/testArray.rb
|
40
|
+
- test/testBuffer.rb
|
41
|
+
- test/testConsole.rb
|
42
|
+
- test/testR4rb.rb
|
43
|
+
- test/testRVect.rb
|
44
|
+
- test/testRserve.rb
|
45
|
+
- test/test_error.rb
|
46
|
+
- script/README
|
47
|
+
- script/Rserv
|
48
|
+
- script/install_Rserv
|
49
|
+
homepage: http://cqls.upmf-grenoble.fr
|
50
|
+
licenses: []
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
- ext/R4rb
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements:
|
68
|
+
- none
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.0.14
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: R for ruby
|
74
|
+
test_files: []
|