rsruby 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/License.txt +504 -0
- data/Manifest.txt +37 -0
- data/README.txt +96 -0
- data/examples/arrayfields.rb +50 -34
- data/examples/bioc.rb +34 -98
- data/examples/dataframe.rb +34 -14
- data/examples/erobj.rb +29 -15
- data/ext/{rsruby/Converters.c → Converters.c} +50 -25
- data/ext/{rsruby/Converters.h → Converters.h} +3 -0
- data/ext/{rsruby/R_eval.c → R_eval.c} +0 -0
- data/ext/{rsruby/R_eval.h → R_eval.h} +0 -0
- data/ext/{rsruby/extconf.rb → extconf.rb} +0 -7
- data/ext/{rsruby/robj.c → robj.c} +0 -0
- data/ext/{rsruby/rsruby.c → rsruby.c} +12 -26
- data/ext/{rsruby/rsruby.h → rsruby.h} +0 -0
- data/lib/rsruby.rb +49 -125
- data/lib/rsruby/dataframe.rb +11 -6
- data/lib/rsruby/erobj.rb +18 -10
- data/lib/rsruby/robj.rb +7 -2
- data/test/table.txt +4 -0
- data/test/tc_array.rb +13 -16
- data/test/tc_boolean.rb +5 -8
- data/test/tc_cleanup.rb +11 -13
- data/test/tc_eval.rb +9 -5
- data/test/tc_extensions.rb +26 -0
- data/test/tc_io.rb +7 -10
- data/test/tc_library.rb +6 -6
- data/test/tc_modes.rb +131 -79
- data/test/tc_robj.rb +26 -29
- data/test/tc_sigint.rb +1 -1
- data/test/tc_to_r.rb +57 -60
- data/test/tc_to_ruby.rb +62 -65
- data/test/tc_vars.rb +14 -14
- data/test/test_all.rb +21 -0
- metadata +34 -40
- data/README +0 -102
data/test/tc_robj.rb
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'rsruby'
|
3
3
|
|
4
|
-
unless $r
|
5
|
-
$r = RSRuby.instance
|
6
|
-
end
|
7
|
-
|
8
4
|
class TestRObj < Test::Unit::TestCase
|
9
5
|
|
10
6
|
def setup
|
7
|
+
@r = RSRuby.instance
|
11
8
|
RSRuby.set_default_mode(RSRuby::NO_DEFAULT)
|
12
|
-
|
13
|
-
|
9
|
+
@r.class_table.clear
|
10
|
+
@r.proc_table.clear
|
14
11
|
end
|
15
12
|
|
16
13
|
def test_type
|
17
|
-
assert_equal(
|
14
|
+
assert_equal(@r.array.class, RObj)
|
18
15
|
end
|
19
16
|
|
20
17
|
def test_call
|
@@ -25,8 +22,8 @@ class TestRObj < Test::Unit::TestCase
|
|
25
22
|
#TODO - In RPy keyword parameters are converted like the method calls
|
26
23
|
#In ruby this isn't such a problem because you can use quoted strings
|
27
24
|
#but we will implement it anyway.
|
28
|
-
|
29
|
-
d =
|
25
|
+
@r.list.autoconvert(RSRuby::BASIC_CONVERSION)
|
26
|
+
d = @r.list(:foo => 'foo', :bar_foo => 'bar.foo', :print_ => 'print', :as_data_frame => 'as.data.frame')
|
30
27
|
d.each do |k,v|
|
31
28
|
assert_equal(k, d[k])
|
32
29
|
end
|
@@ -34,54 +31,54 @@ class TestRObj < Test::Unit::TestCase
|
|
34
31
|
|
35
32
|
def test_bad_keyword_parameters
|
36
33
|
#TODO?
|
37
|
-
#assert_raises(ArgumentError){
|
34
|
+
#assert_raises(ArgumentError){@r.list(:none => 1)}
|
38
35
|
end
|
39
36
|
|
40
37
|
def test_name_conversions
|
41
|
-
assert_equal(
|
42
|
-
assert_equal(
|
43
|
-
assert_equal(
|
44
|
-
assert_equal(
|
38
|
+
assert_equal(@r.array, @r['array'])
|
39
|
+
assert_equal(@r.print_,@r['print'])
|
40
|
+
assert_equal(@r.as_data_frame, @r['as.data.frame'])
|
41
|
+
assert_equal(@r.attr__, @r['attr<-'])
|
45
42
|
end
|
46
43
|
|
47
44
|
def test_not_found
|
48
|
-
assert_raises(RException){
|
45
|
+
assert_raises(RException){@r.foo}
|
49
46
|
end
|
50
47
|
|
51
48
|
def test_name_length_one
|
52
|
-
assert_nothing_raised{
|
49
|
+
assert_nothing_raised{@r.T}
|
53
50
|
end
|
54
51
|
|
55
52
|
def test_autoconvert
|
56
|
-
|
57
|
-
assert_equal(
|
58
|
-
|
59
|
-
assert_equal(
|
53
|
+
@r.seq.autoconvert(RSRuby::BASIC_CONVERSION)
|
54
|
+
assert_equal(@r.seq(10), (1..10).to_a)
|
55
|
+
@r.seq.autoconvert(RSRuby::NO_CONVERSION)
|
56
|
+
assert_equal(@r.seq(10).class, RObj)
|
60
57
|
end
|
61
58
|
|
62
59
|
def test_bad_autoconvert
|
63
|
-
assert_raises(ArgumentError){
|
60
|
+
assert_raises(ArgumentError){@r.seq.autoconvert(RSRuby::TOP_CONVERSION+1)}
|
64
61
|
end
|
65
62
|
|
66
63
|
def test_get_autoconvert
|
67
|
-
|
68
|
-
mode =
|
64
|
+
@r.seq.autoconvert(RSRuby::BASIC_CONVERSION)
|
65
|
+
mode = @r.seq.autoconvert
|
69
66
|
assert_equal(mode, RSRuby::BASIC_CONVERSION)
|
70
67
|
end
|
71
68
|
|
72
69
|
def test_r_gc
|
73
70
|
#TODO - How can this work?
|
74
|
-
|
75
|
-
arr =
|
76
|
-
|
77
|
-
assert(
|
71
|
+
@r.seq.autoconvert(RSRuby::NO_CONVERSION)
|
72
|
+
arr = @r.seq(100000)
|
73
|
+
@r.gc
|
74
|
+
assert(@r['['].call(arr,10))
|
78
75
|
end
|
79
76
|
|
80
77
|
def test_lcall
|
81
78
|
RSRuby.set_default_mode(RSRuby::NO_CONVERSION)
|
82
|
-
arr =
|
79
|
+
arr = @r.c.lcall([['',0],['a',1],['b',2],['c',3]])
|
83
80
|
RSRuby.set_default_mode(RSRuby::BASIC_CONVERSION)
|
84
|
-
assert_equal(
|
81
|
+
assert_equal(@r.names(arr), ['','a','b','c'])
|
85
82
|
end
|
86
83
|
|
87
84
|
end
|
data/test/tc_sigint.rb
CHANGED
data/test/tc_to_r.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'rsruby'
|
3
3
|
|
4
|
-
unless $r
|
5
|
-
$r = RSRuby.instance
|
6
|
-
end
|
7
|
-
|
8
4
|
class Foo
|
9
5
|
end
|
10
6
|
|
@@ -20,114 +16,115 @@ end
|
|
20
16
|
class TestToR < Test::Unit::TestCase
|
21
17
|
|
22
18
|
def setup
|
19
|
+
@r = RSRuby.instance
|
23
20
|
RSRuby.set_default_mode(RSRuby::NO_DEFAULT)
|
24
21
|
end
|
25
22
|
|
26
23
|
def test_robj_to_r
|
27
24
|
|
28
|
-
|
25
|
+
@r.c.autoconvert(RSRuby::NO_CONVERSION)
|
29
26
|
|
30
|
-
r1 =
|
31
|
-
r2 =
|
32
|
-
r3 =
|
27
|
+
r1 = @r.c(4)
|
28
|
+
r2 = @r.c('foo')
|
29
|
+
r3 = @r.c(['a','b'])
|
33
30
|
|
34
|
-
assert(
|
35
|
-
assert(
|
36
|
-
assert(
|
31
|
+
assert(@r['=='].call(r1,4))
|
32
|
+
assert(@r['=='].call(r2,'foo'))
|
33
|
+
assert(@r['=='].call(r3,['a','b']))
|
37
34
|
|
38
|
-
assert_equal(
|
39
|
-
assert_equal(
|
40
|
-
assert_equal(
|
35
|
+
assert_equal(@r.typeof(@r.eval),'closure')
|
36
|
+
assert_equal(@r.typeof(@r.eval(@r.eval)), 'closure')
|
37
|
+
assert_equal(@r.typeof(@r.eval([@r.eval,@r.eval])), 'list')
|
41
38
|
|
42
39
|
#Same tests as above in basic mode - should be identical
|
43
|
-
|
40
|
+
@r.c.autoconvert(RSRuby::BASIC_CONVERSION)
|
44
41
|
|
45
|
-
r1 =
|
46
|
-
r2 =
|
47
|
-
r3 =
|
42
|
+
r1 = @r.c(4)
|
43
|
+
r2 = @r.c('foo')
|
44
|
+
r3 = @r.c(['a','b'])
|
48
45
|
|
49
|
-
assert(
|
50
|
-
assert(
|
51
|
-
assert(
|
46
|
+
assert(@r['=='].call(r1,4))
|
47
|
+
assert(@r['=='].call(r2,'foo'))
|
48
|
+
assert(@r['=='].call(r3,['a','b']))
|
52
49
|
|
53
|
-
assert_equal(
|
54
|
-
assert_equal(
|
55
|
-
assert_equal(
|
50
|
+
assert_equal(@r.typeof(@r.eval),'closure')
|
51
|
+
assert_equal(@r.typeof(@r.eval(@r.eval)), 'closure')
|
52
|
+
assert_equal(@r.typeof(@r.eval([@r.eval,@r.eval])), 'list')
|
56
53
|
|
57
54
|
end
|
58
55
|
|
59
56
|
def test_empty_array_to_null
|
60
|
-
assert(
|
57
|
+
assert(@r.is_null([]))
|
61
58
|
end
|
62
59
|
|
63
60
|
def test_boolean_to_logical
|
64
|
-
assert_equal(
|
65
|
-
assert_equal(
|
66
|
-
assert_equal(
|
67
|
-
assert_equal(
|
61
|
+
assert_equal(@r.c(true),true)
|
62
|
+
assert_equal(@r.c(true).class,true.class)
|
63
|
+
assert_equal(@r.c(false),false)
|
64
|
+
assert_equal(@r.c(false).class,false.class)
|
68
65
|
end
|
69
66
|
|
70
67
|
def test_int_to_int
|
71
|
-
|
72
|
-
assert_equal(
|
73
|
-
|
74
|
-
assert_equal(
|
68
|
+
@r.c.autoconvert(RSRuby::NO_CONVERSION)
|
69
|
+
assert_equal(@r.typeof(@r.c(4)), 'integer')
|
70
|
+
@r.c.autoconvert(RSRuby::BASIC_CONVERSION)
|
71
|
+
assert_equal(@r.typeof(@r.c(4)), 'integer')
|
75
72
|
end
|
76
73
|
|
77
74
|
def test_float_to_float
|
78
|
-
|
79
|
-
assert_equal(
|
80
|
-
|
81
|
-
assert_equal(
|
75
|
+
@r.c.autoconvert(RSRuby::NO_CONVERSION)
|
76
|
+
assert_equal(@r.typeof(@r.c(4.5)), 'double')
|
77
|
+
@r.c.autoconvert(RSRuby::BASIC_CONVERSION)
|
78
|
+
assert_equal(@r.typeof(@r.c(4.5)), 'double')
|
82
79
|
end
|
83
80
|
|
84
81
|
def test_char_to_char
|
85
|
-
|
86
|
-
assert_equal(
|
87
|
-
|
88
|
-
assert_equal(
|
82
|
+
@r.c.autoconvert(RSRuby::NO_CONVERSION)
|
83
|
+
assert_equal(@r.typeof(@r.c('foo')), 'character')
|
84
|
+
@r.c.autoconvert(RSRuby::BASIC_CONVERSION)
|
85
|
+
assert_equal(@r.typeof(@r.c('foo')), 'character')
|
89
86
|
end
|
90
87
|
|
91
88
|
def test_hash_to_named_vector
|
92
|
-
|
93
|
-
assert_equal(
|
94
|
-
assert(
|
95
|
-
assert(
|
89
|
+
@r.c.autoconvert(RSRuby::NO_CONVERSION)
|
90
|
+
assert_equal(@r.typeof(@r.c(:foo => 5, :bar => 7)),'integer')
|
91
|
+
assert(@r.attributes(@r.c(:foo => 5, :bar => 7))['names'].include?('foo'))
|
92
|
+
assert(@r.attributes(@r.c(:foo => 5, :bar => 7))['names'].include?('bar'))
|
96
93
|
#TODO - these fail because of the different calling semantics in
|
97
94
|
#RSRuby
|
98
|
-
|
99
|
-
#assert_equal(
|
100
|
-
#assert(
|
101
|
-
#assert(
|
95
|
+
#@r.c.autoconvert(RSRuby::BASIC_CONVERSION)
|
96
|
+
#assert_equal(@r.typeof(@r.c(:foo => 5, :bar => 7)),'integer')
|
97
|
+
#assert(@r.attributes(@r.c(:foo => 5, :bar => 7))['names'].include?('foo'))
|
98
|
+
#assert(@r.attributes(@r.c(:foo => 5, :bar => 7))['names'].include?('bar'))
|
102
99
|
end
|
103
100
|
|
104
101
|
def test_array_to_vector
|
105
|
-
|
106
|
-
assert_equal(
|
107
|
-
|
108
|
-
assert_equal(
|
102
|
+
@r.c.autoconvert(RSRuby::NO_CONVERSION)
|
103
|
+
assert_equal(@r.length(@r.c(1,2,3,4)),4)
|
104
|
+
@r.c.autoconvert(RSRuby::BASIC_CONVERSION)
|
105
|
+
assert_equal(@r.length(@r.c(1,2,3,4)),4)
|
109
106
|
end
|
110
107
|
|
111
108
|
def test_not_convertible
|
112
109
|
#TODO - range?
|
113
|
-
assert_raises(ArgumentError){
|
110
|
+
assert_raises(ArgumentError){@r.c(1..10)}
|
114
111
|
end
|
115
112
|
|
116
113
|
def test_instances_not_convertible
|
117
114
|
foo = Foo.new
|
118
|
-
assert_raises(ArgumentError){
|
115
|
+
assert_raises(ArgumentError){@r.c(foo)}
|
119
116
|
end
|
120
117
|
|
121
118
|
def test_as_r_method
|
122
|
-
|
119
|
+
@r.c.autoconvert(RSRuby::BASIC_CONVERSION)
|
123
120
|
|
124
121
|
a = Bar.new(3)
|
125
122
|
b = Bar.new('foo')
|
126
|
-
d = Bar.new(
|
123
|
+
d = Bar.new(@r.seq)
|
127
124
|
|
128
|
-
assert_equal(
|
129
|
-
assert_equal(
|
130
|
-
assert_equal(
|
125
|
+
assert_equal(@r.c(a),3)
|
126
|
+
assert_equal(@r.c(b),'foo')
|
127
|
+
assert_equal(@r.c(d).call(1,3),[1,2,3])
|
131
128
|
|
132
129
|
end
|
133
130
|
|
data/test/tc_to_ruby.rb
CHANGED
@@ -1,51 +1,48 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'rsruby'
|
3
3
|
|
4
|
-
unless $r
|
5
|
-
$r = RSRuby.instance
|
6
|
-
end
|
7
|
-
|
8
4
|
class TestToRuby < Test::Unit::TestCase
|
9
5
|
|
10
6
|
def setup
|
7
|
+
@r = RSRuby.instance
|
11
8
|
RSRuby.set_default_mode(RSRuby::NO_DEFAULT)
|
12
|
-
|
13
|
-
|
9
|
+
@r.seq.autoconvert(RSRuby::BASIC_CONVERSION)
|
10
|
+
@r.c.autoconvert(RSRuby::BASIC_CONVERSION)
|
14
11
|
end
|
15
12
|
|
16
13
|
def test_null_to_nil
|
17
|
-
assert(
|
14
|
+
assert(@r.attributes(@r.seq).nil?)
|
18
15
|
end
|
19
16
|
|
20
17
|
def test_factor_to_list
|
21
|
-
assert_equal(
|
22
|
-
assert_equal(
|
23
|
-
assert_equal(
|
18
|
+
assert_equal(@r.factor([1,2,3,4]), ['1','2','3','4'])
|
19
|
+
assert_equal(@r.factor([1,1,1,2]), ['1','1','1','2'])
|
20
|
+
assert_equal(@r.factor(['a','b','c']), ['a','b','c'])
|
24
21
|
end
|
25
22
|
|
26
23
|
def test_NA_int
|
27
24
|
#The formula on right should equal smallest Fixnum
|
28
25
|
#in current Ruby build (can vary)
|
29
|
-
assert_equal(
|
30
|
-
assert(
|
26
|
+
assert_equal(@r.NA, (-1)*(2**((1.size*8)-1)))
|
27
|
+
assert(@r.is_na(@r.NA))
|
31
28
|
end
|
32
29
|
|
33
30
|
def test_NA_string
|
34
|
-
assert_equal(
|
35
|
-
assert_equal(
|
36
|
-
assert_equal(
|
31
|
+
assert_equal(@r.eval_R('as.character(NA)'), 'NA')
|
32
|
+
assert_equal(@r.as_character(@r.NA), 'NA')
|
33
|
+
assert_equal(@r.as_character(@r.NaN), 'NaN')
|
37
34
|
end
|
38
35
|
|
39
36
|
def test_factor_NA
|
40
|
-
assert_equal(
|
41
|
-
assert_equal(
|
42
|
-
assert_equal(
|
37
|
+
assert_equal(@r.factor(@r.NA) , 'NA')
|
38
|
+
assert_equal(@r.factor(@r.NaN), 'NaN')
|
39
|
+
assert_equal(@r.factor(@r.as_character('NA')), 'NA')
|
43
40
|
|
44
|
-
xi = [1,2
|
45
|
-
assert_equal(
|
41
|
+
xi = [1,2,@r.NA,@r.NaN,4]
|
42
|
+
assert_equal(@r.factor(xi), ['1','2','NA','NaN','4'])
|
46
43
|
|
47
|
-
xd = [1.01,2.02
|
48
|
-
assert_equal(
|
44
|
+
xd = [1.01,2.02,@r.NA,@r.NaN,4.04]
|
45
|
+
assert_equal(@r.factor(xd), ['1.01','2.02','NA','NaN','4.04'])
|
49
46
|
|
50
47
|
end
|
51
48
|
|
@@ -55,25 +52,25 @@ class TestToRuby < Test::Unit::TestCase
|
|
55
52
|
#The conversion between NA/NaN and Ruby seems a little confused
|
56
53
|
#at the moment
|
57
54
|
|
58
|
-
xi = [1,2
|
59
|
-
assert_equal(
|
60
|
-
#assert_equal(
|
61
|
-
#assert_equal(
|
62
|
-
assert_equal(
|
63
|
-
assert_equal(
|
55
|
+
xi = [1,2,@r.NA,@r.NaN,4]
|
56
|
+
assert_equal(@r.as_character(xi), ['1','2','NA','NaN','4'])
|
57
|
+
#assert_equal(@r.as_numeric(xi) , [1.0,2.0,@r.NA,@r.NaN,4.0])
|
58
|
+
#assert_equal(@r.as_integer(xi) , [1,2,@r.NA,@r.NaN,4])
|
59
|
+
assert_equal(@r.factor(xi) , ['1','2','NA','NaN','4'])
|
60
|
+
assert_equal(@r.is_na(xi) , [false, false, true, true, false])
|
64
61
|
|
65
|
-
xd = [1.01,2.02
|
66
|
-
assert_equal(
|
67
|
-
#assert_equal(
|
68
|
-
assert_equal(
|
69
|
-
assert_equal(
|
70
|
-
assert_equal(
|
62
|
+
xd = [1.01,2.02,@r.NA,@r.NaN,4.04]
|
63
|
+
assert_equal(@r.as_character(xd), ['1.01','2.02','NA','NaN','4.04'])
|
64
|
+
#assert_equal(@r.as_numeric(xi) , [1.01,2.01,@r.NA,@r.NaN,4.01])
|
65
|
+
assert_equal(@r.as_integer(xd) , [1,2,@r.NA,@r.NA,4])
|
66
|
+
assert_equal(@r.factor(xd) , ['1.01','2.02','NA','NaN','4.04'])
|
67
|
+
assert_equal(@r.is_na(xd) , [false, false, true, true, false])
|
71
68
|
end
|
72
69
|
|
73
70
|
#TODO - table.txt?????????
|
74
71
|
def test_dataframe_to_list
|
75
|
-
|
76
|
-
assert_equal(
|
72
|
+
@r.read_table.autoconvert(RSRuby::BASIC_CONVERSION)
|
73
|
+
assert_equal(@r.read_table("test/table.txt", {:header => 1}),
|
77
74
|
{
|
78
75
|
'A' => ['X1','X2','X3'],
|
79
76
|
'C' => [5,8,2],
|
@@ -83,73 +80,73 @@ class TestToRuby < Test::Unit::TestCase
|
|
83
80
|
end
|
84
81
|
|
85
82
|
def test_logical_to_boolean
|
86
|
-
assert_equal(
|
87
|
-
assert_equal(
|
88
|
-
assert_equal(
|
89
|
-
assert_equal(
|
83
|
+
assert_equal(@r.TRUE, true)
|
84
|
+
assert_equal(@r.T, true)
|
85
|
+
assert_equal(@r.FALSE, false)
|
86
|
+
assert_equal(@r.F, false)
|
90
87
|
end
|
91
88
|
|
92
89
|
def test_int_to_int
|
93
|
-
assert_equal(
|
94
|
-
assert_equal(
|
90
|
+
assert_equal(@r.as_integer(5),5)
|
91
|
+
assert_equal(@r.as_integer(-3),-3)
|
95
92
|
end
|
96
93
|
|
97
94
|
def test_float_to_float
|
98
|
-
assert_equal(
|
99
|
-
assert_equal(
|
100
|
-
assert_equal(
|
95
|
+
assert_equal(@r.as_real(5),5.0)
|
96
|
+
assert_equal(@r.as_real(3.1),3.1)
|
97
|
+
assert_equal(@r.as_real(-3.1), -3.1)
|
101
98
|
end
|
102
99
|
|
103
100
|
def test_complex_to_complex
|
104
101
|
#TODO - Think about Complex support
|
105
|
-
assert_equal(
|
106
|
-
assert_equal(
|
102
|
+
assert_equal(@r.as_complex(Complex(1,2)), Complex(1,2))
|
103
|
+
assert_equal(@r.as_complex(Complex(1.5,-3.4)), Complex(1.5,-3.4))
|
107
104
|
end
|
108
105
|
|
109
106
|
def test_str_to_str
|
110
|
-
|
111
|
-
assert_equal(
|
107
|
+
@r.as_data_frame.autoconvert(RSRuby::NO_CONVERSION)
|
108
|
+
assert_equal(@r.class_(@r.as_data_frame([1,2,3])), 'data.frame')
|
112
109
|
end
|
113
110
|
|
114
111
|
def test_vector_length_one
|
115
|
-
assert_equal(
|
116
|
-
assert_equal(
|
112
|
+
assert_equal(@r.c(1),1)
|
113
|
+
assert_equal(@r.c('foo'),'foo')
|
117
114
|
end
|
118
115
|
|
119
116
|
def test_int_vector_to_array
|
120
|
-
assert_equal(
|
117
|
+
assert_equal(@r.seq(10),[1,2,3,4,5,6,7,8,9,10])
|
121
118
|
end
|
122
119
|
|
123
120
|
def test_float_vector_to_array
|
124
|
-
assert_equal(
|
121
|
+
assert_equal(@r.seq(1,2,{:by => 0.5}), [1.0,1.5,2.0])
|
125
122
|
end
|
126
123
|
|
127
124
|
def test_complex_vector_to_array
|
128
|
-
assert_equal(
|
125
|
+
assert_equal(@r.c(Complex(1,2),Complex(2,-3)),[Complex(1,2),Complex(2,-3)])
|
129
126
|
end
|
130
127
|
|
131
128
|
def test_str_vector_to_array
|
132
|
-
assert_equal(
|
129
|
+
assert_equal(@r.c('Foo','Bar'),['Foo','Bar'])
|
133
130
|
end
|
134
131
|
|
135
132
|
def test_list_to_array
|
136
|
-
|
137
|
-
assert_equal(
|
133
|
+
@r.list.autoconvert(RSRuby::BASIC_CONVERSION)
|
134
|
+
assert_equal(@r.list(1,2.0,'foo'),[1,2.0,'foo'])
|
138
135
|
end
|
139
136
|
|
140
137
|
def test_named_vector_to_hash
|
141
|
-
|
142
|
-
a =
|
138
|
+
@r.c.autoconvert(RSRuby::NO_CONVERSION)
|
139
|
+
a = @r.attr__(@r.c(1,2,3), 'names', ['foo','bar','baz'])
|
143
140
|
assert_equal(a,{'foo'=>1,'bar'=>2,'baz'=>3})
|
144
|
-
assert_equal(
|
141
|
+
assert_equal(@r.list(:foo => 1, :bar => 2, :baz => 3),{'foo'=>1,'bar'=>2,'baz'=>3})
|
145
142
|
end
|
146
143
|
|
147
144
|
def test_vector_coercion
|
148
|
-
|
149
|
-
assert_equal(
|
150
|
-
assert_equal(
|
151
|
-
assert_equal(
|
152
|
-
assert_equal(
|
145
|
+
@r.c.autoconvert(RSRuby::NO_CONVERSION)
|
146
|
+
assert_equal(@r.typeof(@r.c(1,2,3)), 'integer')
|
147
|
+
assert_equal(@r.typeof(@r.c(1,2.0,3)), 'double')
|
148
|
+
assert_equal(@r.typeof(@r.c(1,Complex(2,3),3)), 'complex')
|
149
|
+
assert_equal(@r.typeof(@r.c(1,'foo',3)), 'character')
|
153
150
|
end
|
154
151
|
|
155
152
|
end
|