The Writing R Extensions manual specifically uses convolve as an
example of calling C from R.
On Sun, May 30, 2010 at 2:08 PM, Gunnar Hellmund <ghellmund at gmail.com>
wrote:> Hi
>
> I have made a R function 'convolve2' for convolution of two real
> valued vectors based on Rs 'convolve' with option
type="open" - see
> below.
> (exp.length and irf.length are variables set in another part of the
program)
>
> I wish to implement the function convolve2 in C and use it in a
> function used from R with .Call - e.g. I need to call fft in C.
> All I can find in the source code is do_fft in Internals.h - but how
> do I use do_fft? Or should I call another C routine (and how)?
>
> How do I solve the problem in the most appropriate way?
>
> convolve2=function2(x,y)
> {
> x<- c(rep.int(0,exp.length-1),x)
> n <- length(y<-c(y, rep.int(0, irf.length -1)))
> x <- fft(fft(x) * Conj(fft(y)), inverse=TRUE)
> return(Re(x)/n)
> }
>
> --
> Best wishes/bedste hilsner
>
> Gunnar Hellmund
>
> cand. scient., PhD
> http://staff.pubhealth.ku.dk/~guhe/
>
> ---
> ?If everyone is thinking alike, then somebody isn't thinking.?
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>