int Rf_initEmbeddedR(int argc, char **argv) { Rf_initialize_R(argc, argv); R_Interactive = TRUE; /* Rf_initialize_R set this based on isatty */ setup_Rmainloop(); return(1); }
static char *RAPIinitialize(void) { // TODO: check for header/library version mismatch? char *e; // set R_HOME for packages etc. We know this from our configure script setenv("R_HOME", RHOME, TRUE); // set some command line arguments { structRstart rp; Rstart Rp = &rp; char *rargv[] = { "R", "--slave", "--vanilla" }; int stat = 0; R_DefParams(Rp); Rp->R_Slave = (Rboolean) TRUE; Rp->R_Quiet = (Rboolean) TRUE; Rp->R_Interactive = (Rboolean) FALSE; Rp->R_Verbose = (Rboolean) FALSE; Rp->LoadSiteFile = (Rboolean) FALSE; Rp->LoadInitFile = (Rboolean) FALSE; Rp->RestoreAction = SA_NORESTORE; Rp->SaveAction = SA_NOSAVE; Rp->NoRenviron = TRUE; stat = Rf_initialize_R(2, rargv); if (stat < 0) { return "Rf_initialize failed"; } R_SetParams(Rp); } /* disable stack checking, because threads will throw it off */ R_CStackLimit = (uintptr_t) -1; /* redirect input/output and set error handler */ R_Outputfile = NULL; R_Consolefile = NULL; /* we do not want R to handle any signal, will interfere with monetdbd */ R_SignalHandlers = 0; /* we want control R's output and input */ ptr_R_WriteConsoleEx = writeConsoleEx; ptr_R_WriteConsole = writeConsole; ptr_R_ReadConsole = NULL; ptr_R_ClearerrConsole = clearRErrConsole; // big boy here setup_Rmainloop(); if ((e = RAPIinstalladdons()) != 0) { return e; } // patch R internals to disallow quit and system. Setting them to NULL produces an error. SET_INTERNAL(install("quit"), R_NilValue); // install.packages() uses system2 to call gcc etc., so we cannot disable it (perhaps store the pointer somewhere just for that?) //SET_INTERNAL(install("system"), R_NilValue); rapiInitialized = true; return NULL; }
int main (int argc, char **argv) { structRstart rp; Rstart Rp = &rp; char Rversion[25], *RHome; 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_setStartTime(); R_DefParams(Rp); if((RHome = get_R_HOME()) == NULL) { fprintf(stderr, "R_HOME must be set in the environment or Registry\n"); exit(1); } Rp->rhome = RHome; Rp->home = getRUser(); Rp->CharacterMode = LinkDLL; Rp->ReadConsole = myReadConsole; Rp->WriteConsole = myWriteConsole; Rp->CallBack = myCallBack; Rp->ShowMessage = askok; Rp->YesNoCancel = askyesnocancel; Rp->Busy = myBusy; Rp->R_Quiet = TRUE; Rp->R_Interactive = FALSE; Rp->RestoreAction = SA_RESTORE; Rp->SaveAction = SA_NOSAVE; R_SetParams(Rp); /* so R_ShowMessage is set */ R_SizeFromEnv(Rp); R_SetParams(Rp); R_set_command_line_arguments(argc, argv); FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE)); signal(SIGBREAK, my_onintr); setup_term_ui(); /* initialize graphapp, eventloop, read Rconsole */ setup_Rmainloop(); #ifdef SIMPLE_CASE run_Rmainloop(); end_Rmainloop(); #else R_ReplDLLinit(); while(R_ReplDLLdo1() > 0) { /* add user actions here if desired */ } /* only get here on EOF (not q()) */ R_CleanUp(SA_DEFAULT, 0, 1); #endif end_Rmainloop(); return 0; }
int main (int argc, char **argv) { structRstart rp; Rstart Rp = &rp; char Rversion[25], *RHome; snprintf(Rversion, 25, "%s.%s", R_MAJOR, R_MINOR); if(strcmp(getDLLVersion(), Rversion) != 0) { fprintf(stderr, "Error: R.DLL version does not match\n"); exit(1); } R_setStartTime(); R_DefParams(Rp); if((RHome = get_R_HOME()) == NULL) { fprintf(stderr, "R_HOME must be set in the environment or Registry\n"); exit(1); } Rp->rhome = RHome; Rp->home = getRUser(); Rp->CharacterMode = LinkDLL; Rp->ReadConsole = myReadConsole; Rp->WriteConsole = NULL; /* for illustration purposes we use more flexible WriteConsoleEx */ Rp->WriteConsoleEx = myWriteConsoleEx; Rp->CallBack = myCallBack; Rp->ShowMessage = askok; Rp->YesNoCancel = askyesnocancel; Rp->Busy = myBusy; Rp->R_Quiet = TRUE; Rp->R_Interactive = FALSE; Rp->RestoreAction = SA_RESTORE; Rp->SaveAction = SA_NOSAVE; R_SetParams(Rp); R_set_command_line_arguments(argc, argv); FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE)); signal(SIGBREAK, my_onintr); GA_initapp(0, 0); readconsolecfg(); setup_Rmainloop(); #ifdef SIMPLE_CASE run_Rmainloop(); #else R_ReplDLLinit(); while(R_ReplDLLdo1() > 0) { /* add user actions here if desired */ } /* only get here on EOF (not q()) */ #endif Rf_endEmbeddedR(0); return 0; }
/* * Initialises the R interpreter. */ void init_R(int argc, char **argv){ if (RSRUBY_R_HOME) { setenv("R_HOME", RSRUBY_R_HOME, 0); } Rf_initialize_R(argc, argv); R_Interactive = TRUE; R_CStackLimit = (uintptr_t)-1; //disable stack limit checking setup_Rmainloop(); R_Interactive = FALSE; //Remove crash menu (and other interactive R features) }
int initR(int argc, char **argv) { structRstart rp; Rstart Rp = &rp; /* getenv("R_HOME","/Library/Frameworks/R.framework/Resources",1); */ if (!getenv("R_HOME")) { fprintf(stderr, "R_HOME is not set. Please set all required environment variables before running this program.\n"); return -1; } /* this is probably unnecessary, but we could set any other parameters here */ R_DefParams(Rp); Rp->NoRenviron = 0; R_SetParams(Rp); #ifdef RIF_HAS_RSIGHAND R_SignalHandlers=0; #endif { int stat=Rf_initialize_R(argc, argv); if (stat<0) { fprintf(stderr,"Failed to initialize embedded R! (stat=%d)\n",stat); return -1; } } #ifdef RIF_HAS_RSIGHAND R_SignalHandlers=0; #endif #if (R_VERSION >= R_Version(2,3,0)) /* disable stack checking, because threads will thow it off */ R_CStackLimit = (uintptr_t) -1; #endif #ifdef JGR_DEBUG fprintf(stderr,"R primary initialization done. Setting up parameters.\n"); #endif R_Outputfile = NULL; R_Consolefile = NULL; R_Interactive = 1; SaveAction = SA_SAVEASK; /* ptr_R_Suicide = Re_Suicide; */ /* ptr_R_CleanUp = Re_CleanUp; */ ptr_R_ShowMessage = Re_ShowMessage; ptr_R_ReadConsole = Re_ReadConsole; #if (R_VERSION >=R_Version(2,5,0)) ptr_R_WriteConsole = NULL; ptr_R_WriteConsoleEx = Re_WriteConsoleEx; #else ptr_R_WriteConsole = Re_WriteConsole; #endif ptr_R_ResetConsole = Re_ResetConsole; ptr_R_FlushConsole = Re_FlushConsole; ptr_R_ClearerrConsole = Re_ClearerrConsole; ptr_R_Busy = Re_Busy; ptr_R_ShowFiles = Re_ShowFiles; ptr_R_ChooseFile = Re_ChooseFile; ptr_R_loadhistory = Re_loadhistory; ptr_R_savehistory = Re_savehistory; #ifdef JGR_DEBUG fprintf(stderr,"Setting up R event loop\n"); #endif setup_Rmainloop(); #ifdef JGR_DEBUG fprintf(stderr,"R initialized.\n"); #endif return 0; }
int initR(int argc, char **argv) { structRstart rp; Rstart Rp = &rp; char *p; char rhb[MAX_PATH+10]; LONG h; DWORD t,s=MAX_PATH; HKEY k; int cvl; sprintf(Rversion, "%s.%s", R_MAJOR, R_MINOR); cvl=strlen(R_MAJOR)+2; if(strncmp(getDLLVersion(), Rversion, cvl) != 0) { char msg[512]; sprintf(msg, "Error: R.DLL version does not match (DLL: %s, expecting: %s)\n", getDLLVersion(), Rversion); fprintf(stderr, msg); MessageBox(0, msg, "Version mismatch", MB_OK|MB_ICONERROR); return -1; } R_DefParams(Rp); if(getenv("R_HOME")) { strcpy(RHome, getenv("R_HOME")); } else { /* fetch R_HOME from the registry */ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\R-core\\R",0,KEY_QUERY_VALUE,&k)!=ERROR_SUCCESS || RegQueryValueEx(k,"InstallPath",0,&t,RHome,&s)!=ERROR_SUCCESS) { fprintf(stderr, "R_HOME must be set or R properly installed (\\Software\\R-core\\R\\InstallPath registry entry must exist).\n"); MessageBox(0, "R_HOME must be set or R properly installed (\\Software\\R-core\\R\\InstallPath registry entry must exist).\n", "Can't find R home", MB_OK|MB_ICONERROR); return -2; }; sprintf(rhb,"R_HOME=%s",RHome); putenv(rhb); } /* on Win32 this should set R_Home (in R_SetParams) as well */ 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->ReadConsole = Re_ReadConsole; #if R_VERSION >= R_Version(2,5,0) Rp->WriteConsole = NULL; Rp->WriteConsoleEx = Re_WriteConsoleEx; #else Rp->WriteConsole = Re_WriteConsole; #endif #if R_VERSION >= R_Version(2,1,0) Rp->Busy = Re_Busy; Rp->ShowMessage = Re_ShowMessage; Rp->YesNoCancel = myYesNoCancel; #else Rp->busy = Re_Busy; Rp->message = Re_ShowMessage; Rp->yesnocancel = myYesNoCancel; #endif Rp->CallBack = myCallBack; Rp->CharacterMode = LinkDLL; Rp->R_Quiet = FALSE; Rp->R_Interactive = TRUE; Rp->RestoreAction = SA_RESTORE; Rp->SaveAction = SA_SAVEASK; #if R_VERSION < R_Version(2,0,0) Rp->CommandLineArgs = argv; Rp->NumCommandLineArgs = argc; #else R_set_command_line_arguments(argc, argv); #endif /* Rp->nsize = 300000; Rp->vsize = 6e6; */ R_SetParams(Rp); /* so R_ShowMessage is set */ R_SizeFromEnv(Rp); R_SetParams(Rp); #if (R_VERSION >= R_Version(2,3,0)) /* R_SetParams implicitly calls R_SetWin32 which sets the stack start/limit which we need to override */ R_CStackLimit = (uintptr_t) -1; #endif FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE)); signal(SIGBREAK, my_onintr); setup_term_ui(); setup_Rmainloop(); return 0; }
void mainloop(void) { setup_Rmainloop(); run_Rmainloop(); }
int Rf_initEmbeddedR(int argc, char **argv) { Rf_initialize_R(argc, argv); setup_Rmainloop(); return(1); }