The R Project SVN R

Rev

Rev 38839 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14948 duncan 1
/*
2
 Tests the R error handling in an application
3
 which embeds R. Here, we generate the error by calling stop().
4
 We also provide an on.exit() also.
5
 */
6
 
38673 ripley 7
#include "embeddedRCall.h"
38839 ripley 8
#include "R_ext/RStartup.h"
14948 duncan 9
 
10
 
11
int
12
main(int argc, char *argv[])
13
{
38673 ripley 14
    SEXP e;
15
    int errorOccurred;
16
    char *localArgs[] = {"R", "--silent"};
17
    init_R(sizeof(localArgs)/sizeof(localArgs[0]), localArgs);
14948 duncan 18
 
38673 ripley 19
    /*
20
      Evaluates the two expressions:
21
      source("error.R")
22
      and then calls foo()  twice
23
      where foo is defined in the file error.R
24
    */
25
    PROTECT(e = lang2(install("source"), mkString("error.R")));
26
    R_tryEval(e, R_GlobalEnv, &errorOccurred);
27
    UNPROTECT(1);
14948 duncan 28
 
38673 ripley 29
    PROTECT(e = lang1(install("foo")));
38671 ripley 30
    R_tryEval(e, R_GlobalEnv, &errorOccurred);
14948 duncan 31
    fprintf(stderr, "Trying again (yes it will fail also!)\n");fflush(stderr);
38671 ripley 32
    R_tryEval(e, R_GlobalEnv, &errorOccurred);
38673 ripley 33
    UNPROTECT(1);
14948 duncan 34
 
38849 ripley 35
    end_R();
14948 duncan 36
 
38673 ripley 37
    return(0);
14948 duncan 38
}