[R] Fatal error in SJava.

Heinz Grimm grimm.heinz at rcc.ch
Thu Jul 17 15:58:20 CEST 2003


>Dear r-helpers,

>I have been trying to invoke R from Java in a Windows 2000 computer 
>(unfortunately). All my environment variables seem to be properly set, 
>everything seems to be in order, but I obtaining a

>Fatal error: unable to open the base package

>error window.

[...]

>Some time ago I found a number of messages by another person facing the 
>same problems and he said that when R was invoked directly, it could 
>properly read the R_HOME variable, but when invoked from Java, it 
>searched for the base package in the wrong place (a subdirectory of the 
>jre, if my memory is to be trusted).

This was filed as bug 2003. I have exchanged some emails with Professor
Ripley and he convinced me, that it's not a bug in R. The problem is
caused
by SJava, that doesn't invoke R as described in src/gnuwin32/front-ends.
I have appended a new version of REmbedWin.c, based on the samples in
src/gnuwin32/front-ends, that solves this problem. You just have to
recompile
SJava with the new version of REmbedWin.c. I have tested it with
JDK1.3.1 on
Windows 2000, not with JDK1.4.1.


Regards,
Heinz Grimm




/* REmbedWin.C
 * avoids problem with loading base package
 */
/* 27/03/2000 win32-api needs this */
#define NONAMELESSUNION
#include <windows.h>
#include <stdio.h>
#include <config.h>
#include <Rversion.h>
#include <Startup.h>
/* for askok and askyesnocancel */
#include <graphapp/graphapp.h>

/* for signal-handling code */
#include <psignal.h>

/* one way to allow user interrupts: called in ProcessEvents */
#ifdef _MSC_VER
__declspec(dllimport) int UserBreak;
#else
#define UserBreak     (*_imp__UserBreak)
extern int UserBreak;
#endif

/* calls into the R DLL */
extern char *getDLLVersion();
extern void R_DefParams(Rstart);
extern void R_SetParams(Rstart);
extern void setup_term_ui(void);
extern void ProcessEvents(void);
extern void end_Rmainloop(void), R_ReplDLLinit(void);
extern int R_ReplDLLdo1();
extern void run_Rmainloop(void);


/* simple input, simple output */

/* This version blocks all events: a real one needs to call
ProcessEvents
   frequently. See rterm.c and ../system.c for one approach using
   a separate thread for input */
int myReadConsole(char *prompt, char *buf, int len, int addtohistory)
{
    fputs(prompt, stdout);
    fflush(stdout);
    if(fgets(buf, len, stdin)) return 1;
    else return 0;
}

void myWriteConsole(char *buf, int len)
{
    printf("%s", buf);
}

void myCallBack()
{
    /* called during i/o, eval, graphics in ProcessEvents */
}

void myBusy(int which)
{
    /* set a busy cursor ... if which = 1, unset if which = 0 */
}

static void my_onintr(int sig)
{
    UserBreak = 1;
}

void winInit_R()
{
  char *argv[] = {"SJava", "--no-save", "--silent"};
  int argc;
  argc = sizeof(argv)/sizeof(argv[0]);

  structRstart rp;
  Rstart Rp = &rp;
  char Rversion[25], RUser[MAX_PATH], RHome[MAX_PATH], *p;

  sprintf(Rversion, "%s.%s", R_MAJOR, R_MINOR);
  if(strcmp(getDLLVersion(), Rversion) != 0)
  {
    fprintf(stderr, "Error: R.DLL version does not match\n");
    exit(1);
  }

  R_DefParams(Rp);
  if(getenv("R_HOME"))
  {
    strcpy(RHome, getenv("R_HOME"));
  }
  else
  {
    fprintf(stderr, "R_HOME must be set\n");
    exit(1);
  }
  Rp->rhome = RHome;
  /*
   * try R_USER then HOME then working directory
   */
  if (getenv("R_USER"))
  {
    strcpy(RUser, getenv("R_USER"));
  } else
  if (getenv("HOME"))
  {
    strcpy(RUser, getenv("HOME"));
  } else
  if (getenv("HOMEDIR"))
  {
    strcpy(RUser, getenv("HOMEDIR"));
    strcat(RUser, getenv("HOMEPATH"));
  } else
  {
    GetCurrentDirectory(MAX_PATH, RUser);
  }
  p = RUser + (strlen(RUser) - 1);
  if (*p == '/' || *p == '\\') *p = '\0';
  Rp->home = RUser;
  Rp->CharacterMode = LinkDLL;
  Rp->ReadConsole = myReadConsole;
  Rp->WriteConsole = myWriteConsole;
  Rp->CallBack = myCallBack;
  Rp->message = askok;
  Rp->yesnocancel = askyesnocancel;
  Rp->busy = myBusy;

  Rp->R_Quiet = TRUE;
  Rp->R_Interactive = FALSE;
  Rp->RestoreAction = SA_RESTORE;
  Rp->SaveAction = SA_NOSAVE;
  Rp->CommandLineArgs = NULL;
  Rp->NumCommandLineArgs = 0;
  /* Rp->nsize = 300000;
     Rp->vsize = 6e6; */
  R_SetParams(Rp); /* so R_ShowMessage is set */
  R_SizeFromEnv(Rp);
  R_SetParams(Rp);

  FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));

  signal(SIGBREAK, my_onintr);
  setup_term_ui();
  setup_Rmainloop();
  return;
}

This e-mail transmission contains confidential or legally privileged
information that is intended for the addressee(s) only. You are hereby
notified that any disclosure, copying, distribution or use of the
contents of this e-mail is strictly prohibited if you are not the
intended recipient. Please inform the sender and delete the message from
your system if you have received this e-mail transmission in error.
Thank you.




More information about the R-help mailing list