I am trying to write a function in C that will be called by R. Within it I need to take a random sample without replacement from a vector. Is it possible with Rmath.h to use something like sample() in R? If not, does anyone know why I might be getting
Symbol not found: _gsl_rng_mt19937
When I try to dyn.load() code that calls that includes (with the appropriate headers):
#include <gsl/gsl_randist.h>
#include <gsl/gsl_rng.h>
void update_infs (int *inds,
int *inf_times,
int *n,
int *n_inf,
int *locs,
int *Rinds,
double *logmean,
double *logsd,
double *alpha,
double *wts,
int *indices /* a vector 1:n */
) {
...
/* set up GSL RNG */
gsl_rng * rng = gsl_rng_alloc(gsl_rng_mt19937);
/* end of GSL setup */
...
gsl_ran_choose(rng, tmp_inf_me, Rinds[i], indices, *n, sizeof (double));
... }
Likely the shared object needs to be compiled with a command like
and then
or alternatively
This is telling the compiler where to look for headers, and the linker where to find libraries to link against. During compilation and linking the commands should contain the output of
gsl-config --cflagsandgsl-config --libs, along the lines ofduring compilatoin and
during linking. A test of success is
In a package one would have a file
src/Makevarswithand, for Windows where
gsl-configmight not be available but the user has managed to install gsl and set an environment variableLIB_GSL, a filesrc/Makevars.win