I would like to implement some R package written in C code.
C code should:
- take an array (of any type) as input.
- creates an array as a result (of unpredictable size).
What is the best practice of implementing array transfer?
C code is currently being called using .C() . It accesses the array directly from R via a pointer. Unfortunately, this cannot be done for the conclusion, since the size of the output must be known in advance, which is wrong in my case.
Does it make sense to pass an array from C to R through a file? For example, in ramfs, if you use linux?
Update 1: The same issue was discussed here . There was mentioned a possible variant of the returned array with unknown sizes:
The division of the external function into two, at the point before calculating the array, but after the dimensions are known. The first part will return the dimensions, then an empty array will be prepared, then the second part will be executed and the array will be filled in R.
In my case, the full sizes are known only after the execution of all the code, so this method will mean running the C code twice. Guessing the maximum size of the array is also optional.
Update 2: It seems that you can only use this with .Call() , as the authorities should. Here are some good examples: http://www.sfu.ca/~sblay/RC-interface.ppt .
Thanks.
c r
alm
source share