[R] Pass an optional argument from Fortran subroutine to a R wrapper
Kodalore Vijayan, Vineetha W
vwkv13 at mun.ca
Tue Sep 6 21:51:41 CEST 2016
Hello,
I have a Fortran subroutine which uses an optional argument in the call.
subroutine data (n,ns,alpha,covmat,x,y)
integer, intent(in):: n,ns
double precision, intent(in) :: alpha
double precision, intent(in), optional ::covmat(n,ns)
double precision, intent(out) :: x(n),y(n)
....
end subroutine data
I tried the following R wrapper for this subroutine and got an error saying,
Error in array(x, c(length(x), 1L), if (!is.null(names(x)))
list(names(x), :
'data' must be of a vector type, was 'NULL'
I'm not sure if I passed the arguments correctly in the .Fortran() call. I
couldn't find anything helpful online. I would really appreciate any
help/comments.
data1 <- function(n,ns,alpha,covmat=NULL){
tmp <- .Fortran("data",
n = as.integer(n),ns= as.integer(ns)
alpha=as.numeric(alpha),covmat=as.matrix(covmat),
x=as.double(rep(0,n)),y=as.double(rep(0,n)))
)
}
result <- list(x=tmp$x, y=tmp$y)
return(result)
}
Thanks,
Vineetha
[[alternative HTML version deleted]]
More information about the R-help
mailing list