我想将.csv文件读入R.我已经能够将文件的绝对路径发送给R,它将通过下面的PHP代码中的$test
变量返回它。 $r->evalString("data<-read.csv(filetim,header=TRUE)");
返回下面列出的错误。任何想法是什么导致了错误?如何使用Rserve在R中读取R中的.csv文件以在LAMP系统上与PHP进行通信?
<?php
require_once 'rconfig.php';
require 'rConnection.php';
try {
# Connect to R via Rserve
echo '<p>Connecting to Rserve '.RSERVE_HOST;
$r = new Rserve_Connection(RSERVE_HOST);
echo ' Connection OK</p>';
# Associate filename with the file's absolute path
$r->evalString("filetim=('folder/folder/folder/file.csv')");
$r->evalString("filebob=('folder/folder/folder/file2.csv')");
# Check if the filename is being stored
$test = $r->evalString("filebob");
echo $test;
# Read the .csv file into variable "data"
$r->evalString("data<-read.csv(filetim,header=TRUE)");
$r->close();
} catch(Exception $e) {
echo $e;
}
?>
错误:
'Rserve_Exception' with message 'unable to evaluate' in /folder/folder/folder/folder/folder/rConnection.php:239 Stack trace: #0 /folder/folder/folder/folder/folder/rcodetest.php(17): Rserve_Connection->evalString('data<-read.csv(f...') #1 {main}