8 my ($R, $input, $output);
11 ok $R = Statistics::R->new();
15 ok $R->set('x', $input), 'undef';
16 is $R->get('x'), undef;
20 ok $R->set('x', $input);
21 ok $output = $R->get('x'), 'integer';
26 # R default number of digits is 7
27 $input = 0.93945768644;
28 ok $R->set('x', $input), 'real number';
29 ok $output = $R->get('x');
31 is $output, sprintf("%.7f", $input);
34 $input = "apocalypse";
35 ok $R->set('x', $input), 'string';
36 ok $output = $R->get('x');
38 is $output, "apocalypse";
42 ok $R->set('x', $input), 'string with witespace';
43 ok $output = $R->get('x');
45 is $output, "a string";
48 $input = 'gi|57116681|ref|NC_000962.2|';
49 ok $R->set('x', $input), 'number-containing string';
50 ok $output = $R->get('x');
52 is $output, 'gi|57116681|ref|NC_000962.2|';
55 # Mixed arrays are considered as string arrays by R, thus there is no digit limit
56 $input = [123, "a string", 'two strings', 0.93945768644];
57 ok $R->set('x', $input), 'mixed array';
58 ok $output = $R->get('x');
59 is ref($output), 'ARRAY';
61 is $$output[1], "a string";
62 is $$output[2], "two strings";
63 is $$output[3], 0.93945768644;
67 $input = [ q{statistics-r-0.22}, "abc 123 xyz", 'gi|57116681|ref|NC_000962.2|'];
68 ok $R->set('x', $input), 'array of number-containing strings';
69 ok $output = $R->get('x');
70 is ref($output), 'ARRAY';
71 is $$output[0], q{statistics-r-0.22};
72 is $$output[1], "abc 123 xyz";
73 is $$output[2], 'gi|57116681|ref|NC_000962.2|';
76 $input = [123,142,147,153,145,151,165,129,133,150,142,154,131,146,151,136,147,156,141,155,147,165,168,146,148,146,142,145,161,157,154,137,130,161,130,156,140,145,154];
77 ok $R->set('x', $input), 'large array of integers';
78 ok $output = $R->get('x');
79 is ref($output), 'ARRAY';
80 for (my $i = 0; $i < scalar @$input; $i++) {
81 is $$output[$i], $$input[$i];
86 ok $R->set('x', $input), 'data frame';
87 is $R->run(q`a <- data.frame(first=x)`), '';
88 ok $output = $R->get('a$first');
89 is ref($output), 'ARRAY';
95 # Bug reported by Manuel A. Alonso Tarajano
96 is $R->run(q`mydat = seq(1:4)`), '';
97 ok $output = $R->get('mydat');
104 # Strings containing quotes and escaped quotes
105 $input = q{He said: "Let's go \"home\" now!\n"};
106 ok $R->set('x', $input), 'string';
107 ok $output = $R->get('x');
109 is $output, q{He said: "Let's go \"home\" now!\n"};
112 $input = q{He said: "Let's go \\\\\\\\\\\\\"home\\\\\\\\\\\\\" now!\n"};
113 # because \ is a special char that needs to be escaped, this string really is:
114 # He said: "Let's go \\\\\\\"home\\\\\\\" now!\n
115 ok $R->set('x', $input), 'string';
116 ok $output = $R->get('x');
118 is $output, q{He said: "Let's go \\\\\\\\\\\\\"home\\\\\\\\\\\\\" now!\n"};