[R] S_alloc or Calloc for return value

Dirk Eddelbuettel edd at debian.org
Tue Jul 21 16:12:52 CEST 2009


On 21 July 2009 at 06:56, Dan Kelley wrote:
| I'm afraid I am missing something.  In my R function (call it "foo", say) I
| am doing something like 
| 
|      foo <- function() {
|         ...
|         .C("bar", ..., res=integer(n), ...)$res
|     }
| 
| but I don't know the "n" to use; that is determined inside my C function
| "bar".  Is there a way around this?  
| 
| I'm sorry to be thick on this.  Too many decades of C have made me love
| pointers too much, I reckon.

You want the .Call interface which uses SEXP to C/C++ and in return. That way
you create a vector in your code, with the dimension determined at run-time.

Dirk
 
| Dirk Eddelbuettel wrote:
| > 
| > 
| > You want R_alloc(). Here, "end of the call" is the call of the R function
| > that calls your C function. This is what you want---the data will be
| > available for the caller of your C code.
| > 
| > 
| 
| -- 
| View this message in context: http://www.nabble.com/S_alloc-or-Calloc-for-return-value-tp24579062p24588176.html
| Sent from the R help mailing list archive at Nabble.com.
| 
| ______________________________________________
| 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.

-- 
Three out of two people have difficulties with fractions.




More information about the R-help mailing list