Which version of R is this? (See the posting guide, please.)
Some versions of R (e.g. 1.8.0) already had "convolve" loaded and you
need
to use another name or use the PACKAGE argument. It works in the current
1.9.1.
On Wed, 4 Aug 2004, Federico Cantini wrote:
> Hi all,
> i have some problem in using shared objects.
> I tried the example found in "Writing R Extension", pg. 33
>
> I used the .c file prova.c :
>
> -------------------------------------------------------------------
> #include <R.h>
> #include <Rinternals.h>
>
> void convolve(double *a, int *na, double *b, int *nb, double *ab)
> {
> int i, j , nab = *na + *nb - 1;
>
> for (i = 0; i < nab; i++)
> ab[i] = 0.0;
> for (i = 0; i < *na; i++)
> for (j = 0; i < *nb; i++)
> ab[i + j] += a[i] * b [j];
> }
> -------------------------------------------------------------------
>
> I generated shared object with
> R CMD SHLIB prova.c
>
> i run R and so
>
> > dyn.load("prova.so", local = TRUE, now = TRUE)
>
>
>convolve1<-function(a,b).C("convolve",as.double(a),as.integer(length(a)),as.double(b),as.integer(length(b)),ab
= double(length(a) + length(b) - 1)$ab)
>
> > a<-1:10
> > b<-a
>
> typing convolve1(a,b) i get a Segmentation fault.
>
> Can anyone tell me what's the problem
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595