File: Rerror.c

package info (click to toggle)
r-base 4.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112,924 kB
  • sloc: ansic: 291,338; fortran: 111,889; javascript: 14,798; yacc: 6,154; sh: 5,689; makefile: 5,239; tcl: 4,562; perl: 963; objc: 791; f90: 758; asm: 258; java: 31; sed: 1
file content (38 lines) | stat: -rw-r--r-- 937 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 Tests the R error handling in an application
 which embeds R. Here, we generate the error by calling stop().
 We also provide an on.exit() also.
 */

#include "embeddedRCall.h"
#include "R_ext/RStartup.h"


int
main(int argc, char *argv[])
{
    SEXP e;
    int errorOccurred;
    char *localArgs[] = {"R", "--silent"};
    init_R(sizeof(localArgs)/sizeof(localArgs[0]), localArgs);

    /*
      Evaluates the two expressions:
      source("error.R")
      and then calls foo()  twice
      where foo is defined in the file error.R
    */
    PROTECT(e = lang2(install("source"), mkString("error.R")));
    R_tryEval(e, R_GlobalEnv, &errorOccurred);
    UNPROTECT(1);

    PROTECT(e = lang1(install("foo")));
    R_tryEval(e, R_GlobalEnv, &errorOccurred);
    fprintf(stderr, "Trying again (yes it will fail also!)\n");fflush(stderr);
    R_tryEval(e, R_GlobalEnv, &errorOccurred);
    UNPROTECT(1);

    end_R();

    return(0);
}