Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6898571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:18:48+00:00 2026-05-27T07:18:48+00:00

I am trying to plot some graphs using Java and R (JRI and Rengine).

  • 0

I am trying to plot some graphs using Java and R (JRI and Rengine). When I write something like this in my code it works fine:

re.eval("plot(c(1,5,3,8,5), type='l', col=2)");

But if I write this:

re.eval("source(\"C:\\Documents and Settings\\abc\\My Documents\\Test Data\\BoxPlot.r\");");

the output window flashes for a moment and vanishes. This specified file contains only 1 command, as the first one, i.e. re.eval("plot(c(1,5,3,8,5), type='l', col=2)");

I am very new to R, so this may be a very basic question. But I am not able to find it out. Can anyone help me out?

Thanks.

EDIT 1

I am using Windows XP.

Here is the full code:

import org.rosuda.JRI.Rengine;

public class JavaGDExample1 {

  public static void main(String[] args) {
    Rengine re;
    String[] dummyArgs = new String[1];
    dummyArgs[0] = "--vanilla";
    re = new Rengine(dummyArgs, false, null);
    re.eval("library(JavaGD)");

    // This is the critical line: Here, we tell R that the JavaGD() device that
    // it is supposed to draw to is implemented in the class MyJavaGD. If it were
    // in a package (say, my.package), this should be set to
    // my/package/MyJavaGD1.
    re.eval("Sys.putenv('JAVAGD_CLASS_NAME'='MyJavaGD1')");

    re.eval("JavaGD()");
//    re.eval("plot(c(1,5,3,8,5), type='l', col=2)");
    re.eval("source(\"C:\\Documents and Settings\\abc\\My Documents\\Test Data\\BoxPlot.r\");");
//    re.eval("source(\"C:\\Documents and Settings\\abc\\My Documents\\Test Data\\testPlot.r\")");
    re.end();
  }
}


import javax.swing.JFrame;

import org.rosuda.javaGD.GDCanvas;
import org.rosuda.javaGD.GDInterface;

/**
 * This is a minimal reimplementation of the GDInterface. When the device is opened, 
 * it just creates a new JFrame, adds a new GDCanvas to it (R will plot to this GDCanvas)
 * and tells the program to exit when it is closed.   
 */
public class MyJavaGD1 extends GDInterface {
  public JFrame f;

  public void gdOpen(double w, double h) {
    f = new JFrame("JavaGD");
    c = new GDCanvas(w, h);
    f.add((GDCanvas) c);
    f.pack();
    f.setVisible(true);
    f.setTitle("Naked R plot");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:18:48+00:00Added an answer on May 27, 2026 at 7:18 am

    You path is wrong – you’re entering the quoting hell, what you sent to R is

     source("C:\Documents and Settings\abc\My Documents\Test Data\BoxPlot.r");
    

    which is invalid:

     > source("C:\Documents and Settings\abc\My Documents\Test Data\BoxPlot.r");
     Error: '\D' is an unrecognized escape in character string starting "C:\D"
    

    To avoid the quoting hell, it is safer to assign file names:

     re.assign("fn", "c:\\foo\\bar");
     re.eval("source(fn)");
    

    or use / instead of \\

    PS: use stats-rosuda-devel for rJava/JRI questions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create plot some push pins on map using GeoCoordinate as
I'm using GD to plot some simple charts from array point data.. Trying to
I am trying to plot large amounts of points using some library. The points
I am using the MSChart Control to plot some data but I would like
I am trying to plot some waypoints using the Google-Earth toolbox . The documentation
I have a plot (sample code pasted below) that I am trying to add
I'm currently trying to use the core-plot library to graph some data I get
Happy new year to you all! I am plotting some graphs and would like
I'm trying to plot some prices vs dates. There are about 10k lines of
I'm trying to plot a couple of UnitStep functions, but for some reason, Mathematica

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.