File: getScalarInteger.c

package info (click to toggle)
r-cran-mcmc 0.9-5-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,304 kB
  • sloc: ansic: 1,426; makefile: 14; sh: 8
file content (20 lines) | stat: -rw-r--r-- 437 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

#include <R.h>
#include <Rinternals.h>
#include "myutil.h"

int
getScalarInteger(SEXP foo, char *argname)
{
    if (! isNumeric(foo))
        error("argument \"%s\" must be numeric", argname);
    if (LENGTH(foo)  != 1)
        error("argument \"%s\" must be scalar", argname);
    if (isInteger(foo)) {
        return INTEGER(foo)[0];
    } else {
        SEXP bar = coerceVector(foo, INTSXP);
        return INTEGER(bar)[0];
    }
}