9 use File::Spec::Functions;
11 my ($R, $expected, $bin, $version);
15 ok $R = Statistics::R->new();
18 ok $bin =~ /\S+/, 'Executable name';
21 is $R->run( ), $expected;
24 ok $bin =~ /\S+/, 'Executable path';
26 ok $version = $R->version();
27 ok $version =~ /^\d+\.\d+\.\d+$/, 'Version';
29 diag "R version $version found at $bin\n";
33 is $R->run( qq`postscript("$file" , horizontal=FALSE , width=500 , height=500 , pointsize=1)`), $expected, 'Basic';
36 is $R->run( q`plot(c(1, 5, 10), type = "l");` ), $expected;
41 is $R->run( q`dev.off()` ), $expected; # RT bug #66190
43 ok -e $file; # RT bug #70307
50 is $R->run( q`for (j in 1:3) { cat("loop iteration "); cat(j); cat("\n") }` ), $expected;
52 $expected = 'Some innocuous message on stderr';
53 is $R->run( q`write("Some innocuous message on stderr", stderr())` ), $expected, 'IO';
55 $expected = 'Some innocuous message on stdout';
56 is $R->run( q`write("Some innocuous message on stdout", stdout())` ), $expected;
58 $expected = '[1] 123';
59 is $R->run( qq`x <- 123 \n print(x)` ), $expected, 'Multi-line commands';
62 my $cmd1 = 'x <- 456 ; write.table(x, file="", row.names=FALSE, col.names=FALSE)';
63 is $R->run( $cmd1 ), $expected; # RT bug #70314
71 $expected = '[1] "ok"';
72 is $R->run( $cmd2 ), $expected, 'Heredoc commands';
77 is $R->run( $cmd1, $cmd2 ), $expected, 'Multiple commands';
80 'Some innocuous message on stderr
84 Some innocuous message on stdout
89 $file = catfile('t', 'data', 'script.R');
90 is $R->run_from_file( $file ), $expected, 'Command from file (relative path)';
92 my $absfile = File::Temp->new( UNLINK => 1 )->filename;
93 copy($file, $absfile) or die "Error: Could not copy file $file to $absfile: $!\n";
94 is $R->run_from_file( $absfile ), $expected, 'Commands from file (absolute path)';