Passing functions to R as arguments. .Fortran

Having spent several days searching for something similar on the Internet, I still could not find anything that describes this problem. Reading through (otherwise highly recommended) "Writing R-Extensions" also offers a solution. So here is my most pressing question:

Is it possible to pass functions (for simplicity, accept a simple R function - actually the problem is even more ugly) as function parameters / routines for Fortran via a call to .Fortran (...) - and if so, how?

I wrote two simple functions to test this, first the Fortran subroutine (given the use of the function that I originally planned to pass in this way, weird interface sizes):

subroutine foo(o, x)
    implicit none

    interface
        subroutine o(t, y, param, f)
            double precision, intent(in) :: t
            double precision, dimension(58), intent(in) :: y, param
            double precision, dimension(22), intent(out) :: f
        end subroutine
    end interface

    double precision, dimension(22), intent(out) :: x

    double precision, dimension(58) :: yt, paramt
    integer :: i

    do i = 1, 58
        yt(i) = rand(0)
        paramt(i) = rand(1)
    end do

    call o(dble(4.2), yt, paramt, x)
end subroutine

and a simple function R go to the above function:

asdf <- function(a, s, d, f){x <- c(a, s, d, f)}

.Fortran("foo", asdf, vector(mode="numeric", length=22)) Error: invalid mode (closure) to pass to Fortran (arg 1) "asdf" ( ) segfault, ( , ).

FYI, , - ( ), , ( ) R -, .

,

+5
1

R .Fortran. .Call .External R C/++.

C/++ R-, Fortran (. Calling-C-from-FORTRAN-and-vice-versa R ).

+2

All Articles