I am trying to pass the numeric vector from R to an array in PHP.
index.php:
<?php
$n = 3;
$out = array();
exec("Rscript script.R $n", $out);
$length = count($out);
echo "length = ".$length."<br>";
for($i = 0; $i < $length; $i++)
echo "out[$i] = ".$out[$i]
?>
script.R:
#!/usr/bin/env Rscript
i <- as.numeric(commandArgs(TRUE))
print(i:10)
Output:
length = 1
out[0] = [1] 3 4 5 6 7 8 9 10
As you can see from the above output, PHP is storing a R vector as a single element of an array. How do I store the individual elements of a R vector in PHP array?