rserve-client 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +1 -1
- data/Manifest.txt +4 -0
- data/README.txt +1 -2
- data/lib/rserve.rb +1 -1
- data/lib/rserve/rexp/factor.rb +23 -0
- data/lib/rserve/rfactor.rb +62 -0
- metadata +6 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -12,6 +12,7 @@ lib/rserve/protocol.rb
|
|
12
12
|
lib/rserve/protocol/rexpfactory.rb
|
13
13
|
lib/rserve/rexp.rb
|
14
14
|
lib/rserve/rexp/double.rb
|
15
|
+
lib/rserve/rexp/factor.rb
|
15
16
|
lib/rserve/rexp/genericvector.rb
|
16
17
|
lib/rserve/rexp/integer.rb
|
17
18
|
lib/rserve/rexp/language.rb
|
@@ -22,15 +23,18 @@ lib/rserve/rexp/string.rb
|
|
22
23
|
lib/rserve/rexp/symbol.rb
|
23
24
|
lib/rserve/rexp/unknown.rb
|
24
25
|
lib/rserve/rexp/vector.rb
|
26
|
+
lib/rserve/rfactor.rb
|
25
27
|
lib/rserve/rlist.rb
|
26
28
|
lib/rserve/talk.rb
|
27
29
|
spec/rserve_connection_spec.rb
|
28
30
|
spec/rserve_double_spec.rb
|
29
31
|
spec/rserve_integer_spec.rb
|
32
|
+
spec/rserve_logical_spec.rb
|
30
33
|
spec/rserve_packet_spec.rb
|
31
34
|
spec/rserve_protocol_spec.rb
|
32
35
|
spec/rserve_rexp_spec.rb
|
33
36
|
spec/rserve_rexpfactory_spec.rb
|
37
|
+
spec/rserve_rfactor_spec.rb
|
34
38
|
spec/rserve_spec.rb
|
35
39
|
spec/rserve_talk_spec.rb
|
36
40
|
spec/spec.opts
|
data/README.txt
CHANGED
@@ -43,7 +43,7 @@ Cons:
|
|
43
43
|
* Seamless integration with ruby. Every method and object is treated like a Ruby one
|
44
44
|
* Cons:
|
45
45
|
* Transformation between R and Ruby types aren't trivial
|
46
|
-
* Dependent
|
46
|
+
* Dependent on operating system, Ruby implementation and R version
|
47
47
|
* Not available for alternative implementations of Ruby (JRuby, IronRuby and Rubinius)
|
48
48
|
|
49
49
|
|
@@ -54,7 +54,6 @@ Implements
|
|
54
54
|
* REXPs
|
55
55
|
* Enviroment
|
56
56
|
* ExpressionVector
|
57
|
-
* Factor
|
58
57
|
* Raw
|
59
58
|
* Reference
|
60
59
|
* S4
|
data/lib/rserve.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rserve
|
2
|
+
class REXP
|
3
|
+
class Factor < REXP::Integer
|
4
|
+
def initialize(ids,levels,attr=nil)
|
5
|
+
super(ids,attr)
|
6
|
+
@levels = (levels.nil?)? Array.new : levels;
|
7
|
+
@factor = RFactor.new(@payload, @levels, false, 1)
|
8
|
+
end
|
9
|
+
def factor?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
def as_factor
|
13
|
+
@factor
|
14
|
+
end
|
15
|
+
def as_strings
|
16
|
+
@factor.as_strings
|
17
|
+
end
|
18
|
+
def to_s
|
19
|
+
super+"[#{levels.length}]"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Rserve
|
2
|
+
class RFactor
|
3
|
+
attr_reader :ids
|
4
|
+
attr_reader :levels
|
5
|
+
attr_reader :index_base
|
6
|
+
def initialize(i,v,copy,index_base)
|
7
|
+
i=[] if i.nil?
|
8
|
+
v=[] if v.nil?
|
9
|
+
if (copy)
|
10
|
+
@ids=i.dup
|
11
|
+
@levels=v.dup
|
12
|
+
else
|
13
|
+
@ids=i
|
14
|
+
@levels=v
|
15
|
+
end
|
16
|
+
@index_base=index_base
|
17
|
+
end
|
18
|
+
# returns the level of a given case
|
19
|
+
# * @param i case number
|
20
|
+
# * @return name. may throw exception if out of range
|
21
|
+
def [](i)
|
22
|
+
li = @ids[i]-index_base
|
23
|
+
return (li<0 or li>levels.length) ? nil : levels[li]
|
24
|
+
end
|
25
|
+
def contains?(li)
|
26
|
+
li=level_index(li) if li.is_a? String
|
27
|
+
@ids.any? {|v| v==li}
|
28
|
+
end
|
29
|
+
|
30
|
+
# return the index of a given level name or -1 if it doesn't exist
|
31
|
+
def level_index(name)
|
32
|
+
return nil if name.nil?
|
33
|
+
levels.length.times {|i|
|
34
|
+
return i+index_base if !levels[i].nil? and levels[i]==name
|
35
|
+
}
|
36
|
+
return nil
|
37
|
+
end
|
38
|
+
def count(li)
|
39
|
+
li=level_index(li) if li.is_a? String
|
40
|
+
@ids.inject(0) {|ac,v| ac+ ((v==li) ? 1 : 0 ) }
|
41
|
+
end
|
42
|
+
# return a hash with levels as keys and counts as values
|
43
|
+
def counts_hash
|
44
|
+
h=@levels.inject({}) {|ac,v| ac[v]=0;ac}
|
45
|
+
@ids.each {|v| h[@levels[v-index_base]]+=1}
|
46
|
+
h
|
47
|
+
end
|
48
|
+
def as_integers
|
49
|
+
@ids
|
50
|
+
end
|
51
|
+
def as_strings
|
52
|
+
@ids.map {|v| @levels[v-index_base]}
|
53
|
+
end
|
54
|
+
def index_at(i)
|
55
|
+
@ids[i]
|
56
|
+
end
|
57
|
+
def size
|
58
|
+
@ids.length
|
59
|
+
end
|
60
|
+
alias :at :[]
|
61
|
+
end
|
62
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Claudio Bustos
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/rserve/protocol/rexpfactory.rb
|
96
96
|
- lib/rserve/rexp.rb
|
97
97
|
- lib/rserve/rexp/double.rb
|
98
|
+
- lib/rserve/rexp/factor.rb
|
98
99
|
- lib/rserve/rexp/genericvector.rb
|
99
100
|
- lib/rserve/rexp/integer.rb
|
100
101
|
- lib/rserve/rexp/language.rb
|
@@ -105,15 +106,18 @@ files:
|
|
105
106
|
- lib/rserve/rexp/symbol.rb
|
106
107
|
- lib/rserve/rexp/unknown.rb
|
107
108
|
- lib/rserve/rexp/vector.rb
|
109
|
+
- lib/rserve/rfactor.rb
|
108
110
|
- lib/rserve/rlist.rb
|
109
111
|
- lib/rserve/talk.rb
|
110
112
|
- spec/rserve_connection_spec.rb
|
111
113
|
- spec/rserve_double_spec.rb
|
112
114
|
- spec/rserve_integer_spec.rb
|
115
|
+
- spec/rserve_logical_spec.rb
|
113
116
|
- spec/rserve_packet_spec.rb
|
114
117
|
- spec/rserve_protocol_spec.rb
|
115
118
|
- spec/rserve_rexp_spec.rb
|
116
119
|
- spec/rserve_rexpfactory_spec.rb
|
120
|
+
- spec/rserve_rfactor_spec.rb
|
117
121
|
- spec/rserve_spec.rb
|
118
122
|
- spec/rserve_talk_spec.rb
|
119
123
|
- spec/spec.opts
|
metadata.gz.sig
CHANGED
Binary file
|