Skip to content
Prev 326127 / 398503 Next

How to create a function returning an array ?

Please could you explain what you mean by several typos in my code?

Anyway, it works very well and keep in minds that here I just wrote a very simple code to illustrate what I really want since in the reality, the program is more complex than what you see.
May be I'm wrong but I also prefer to call this fortran function because I realized that (i) R is not very efficient for large data sets reading and processing and (ii) the speed of execution in Fortran is faster than in C.

Armel

-----Original Message-----
From: Duncan Murdoch [mailto:murdoch.duncan at gmail.com] 
Sent: Friday, June 28, 2013 9:30 AM
To: Kaptue Tchuente, Armel
Cc: r-help at r-project.org
Subject: Re: [R] How to create a function returning an array ?
On 28/06/2013 10:18 AM, Kaptue Tchuente, Armel wrote:
There are several typos in your code above, but I think your intention is clear.

You can do what you are asking for, but not with .Fortran.  It only handles vectors for input and output.  You'll need to use .Call (which means writing in C or C++).  If you're familiar with C++, using Rcpp is probably the easiest way to do this.  If not, I'd rewrite the Fortran code to avoid the need for the transpose at the end, and do

dim(out$img) <- c(n,m)
return(out$img)

within your read_ts function.  I think this is reasonably efficient.

Duncan Murdoch