Created
March 1, 2018 13:59
-
-
Save anonymous/08b42e83c949e250f60b068d58a3ec51 to your computer and use it in GitHub Desktop.
Simple R program crashes in Win 64 bits when errors in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define Win32 | |
#define WIN32_LEAN_AND_MEAN 1 | |
#include <windows.h> | |
#include <stdio.h> | |
#include <Rversion.h> | |
#define LibExtern __declspec(dllimport) extern | |
#include <Rembedded.h> | |
#include <R_ext/RStartup.h> | |
#include <graphapp.h> | |
int myReadConsole(const char *prompt, char *buf, int len, int addtohistory) | |
{ | |
fputs(prompt, stdout); | |
fflush(stdout); | |
if(fgets(buf, len, stdin)) return 1; | |
else return 0; | |
} | |
void myWriteConsoleEx(const char *buf, int len, int otype){ | |
printf("%s", buf); | |
} | |
void myCallBack(void){} | |
void myBusy(int which){} | |
int main (int argc, char **argv) | |
{ | |
structRstart rp; | |
Rstart Rp = &rp; | |
char *RHome; | |
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; | |
Rp->WriteConsoleEx = myWriteConsoleEx; | |
Rp->CallBack = myCallBack; | |
Rp->ShowMessage = askok; | |
Rp->YesNoCancel = askyesnocancel; | |
Rp->Busy = myBusy; | |
Rp->R_Quiet = FALSE; | |
Rp->R_Interactive = TRUE; | |
Rp->RestoreAction = SA_RESTORE; | |
Rp->SaveAction = SA_NOSAVE; | |
R_SetParams(Rp); | |
R_set_command_line_arguments(argc, argv); | |
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE)); | |
GA_initapp(0, 0); | |
readconsolecfg(); | |
setup_Rmainloop(); | |
R_ReplDLLinit(); | |
while(R_ReplDLLdo1() > 0){} | |
Rf_endEmbeddedR(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment