Rserve与java。 Eval失败错误127

时间:2016-11-10 12:52:24

标签: java r rserve

我收到此错误,我不知道该怎么做,无法在此网站上找到任何其他解决方案。我在计算机的后台运行Rserve,然后连接到本地主机。但我不能让框架弹出。
这是我的代码:

package rservedemo;

/**
 *
 * @author Carl
 */
import java.awt.*;

import java.awt.event.*;
import org.rosuda.REngine.*;
import org.rosuda.REngine.Rserve.*;

public class PlotDemo extends Canvas {


public static void main(String[] args) {

try 
{
    String device = "jpeg";
    RConnection c = new RConnection ((args.length>0)?args[0]:"127.0.0.1");
    if
            (c.parseAndEval("supressWarnings(require('Cairo',quietly=TRUE))").asInteger()>0) device="CarioJPEG";

    else
        System.out.println("(Consider installing Cairo package for better bitmap output)");

       REXP xp = c.parseAndEval("Try("+device+"('test.jpg,quality=90))");
       if (xp.inherits("Try error"))
       {
           System.err.println("Can't open "+device+" graphics device:\n" +xp.asString());

       REXP w = c.eval("If (exists('last.warning') && length(last.warning)>0)names(last.warning) [1] else 0");
       if (w.isString()) System.err.println(w.asString());
       return;
       }
       c.parseAndEval("data(iris); plot(iris$Sepal.Length, iris$Petal.Length); dev.off()");

       xp = c.parseAndEval("r=readBin('test.jpg','raw',1024*1024); unlink('test.jpg');r");

       Image img = Toolkit.getDefaultToolkit().createImage(xp.asBytes());
       Frame f = new Frame("Test image");
       f.add(new PlotDemo (img));

       f.addWindowListener(new WindowAdapter(){
           public void windowClosing(WindowEvent e){System.exit(0);}

       });
       f.pack();
       f.setVisible(true);
       c.close();

}
catch (RserveException rse)
        {
            System.out.println(rse);
        }
    catch (REXPMismatchException mme)
    {
        System.out.println(mme);
        mme.printStackTrace();
    }
catch (Exception e)

{
    System.out.println("Seomthing went wrong, but it's not Rserve: " +e.getMessage());
    e.printStackTrace();
}

    }
    Image img;
    public PlotDemo(Image img)
    {
        this.img=img;
        MediaTracker mediaTracker = new MediaTracker(this);
        mediaTracker.addImage(img, 0);
        try
        {
            mediaTracker.waitForID(0);
        }
        catch (InterruptedException ie)
        {
            System.err.println(ie);
            System.exit(1);
        }
        setSize(img.getWidth(null), img.getHeight(null));      
    }
    public void paint (Graphics g)
    {
        g.drawImage(img, 0, 0, null);
    }
}

这是错误,我试图改变27行,但无法做任何有用的事情。当我运行

c.parseAndEval("data(iris); plot(iris$Sepal.Length, iris$Petal.Length); dev.off()"); 
在r中,它有效。因此,剂量似乎是问题所在。

 Seomthing went wrong, but it's not Rserve: eval failed, request status: error code: 127
org.rosuda.REngine.REngineException: eval failed, request status: error code: 127
    at org.rosuda.REngine.Rserve.RConnection.parseAndEval(RConnection.java:454)
    at org.rosuda.REngine.REngine.parseAndEval(REngine.java:108)
    at rservedemo.PlotDemo.main(PlotDemo.java:27)

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

通常,处理退出代码127表示File not found。 在你的情况下有问题可以是行:

REXP xp = c.parseAndEval("Try("+device+"('test.jpg,quality=90))");

因为你可能有错误(拼写错误):

(c.parseAndEval("supressWarnings(require('Cairo',quietly=TRUE))").asInteger()>0) device="CarioJPEG";

注意:CarioJPEG而不是CairoJPEG