Explore Connect Documentation
Snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <R.h>
#include <Rinternals.h>
#include <Rmath.h>
#include <math.h>
SEXP fooC2(SEXP aR, SEXP  bR)
{ 
  int i, j, n = length(aR);
  double *a = REAL(aR), *b = REAL(bR);
  SEXP Rval = allocVector(REALSXP, n);
  
  for (i = 0; i < n; i++) {
    REAL(Rval)[i] = 0;
    for (j = 0; j < n; j++)
      REAL(Rval)[i] += pow(a[j] + i + 1, b[j]);
  }
  return Rval;
}
Press desired key combination and then press ENTER.
1
dyn.load("chapter7/fooC2.so")  # load the compiled C code
Press desired key combination and then press ENTER.