Using .Fortran() from R package with error saying

2019-06-13 22:50发布

I tried the following codes:

library(quantreg) # to load the package
library(foreign)  # to load the package

.Fortran("rqfn", PACKAGE = "quantreg")

but I get the following error:

Error in .Fortran("rqfn", PACKAGE = "quantreg") : 
"rqfn" not available for .Fortran() for package "quantreg"

I have installed Rtools. But it does not solve the problem. I also checked the issues concerning system paths (as in this site: https://github.com/stan-dev/rstan/wiki/Install-Rtools-for-Windows), but there is no problem about that. Could anyone give me a hand? Thank you very much.

1条回答
贪生不怕死
2楼-- · 2019-06-13 23:13

You can build your own library:

  • Download rqfn.f and rqfnb.f. The latter is needed for stepy method.
  • Call R CMD SHLIB rqfn.f rqfnb.f
  • use the function like this:

    data(stackloss)
    x <- stack.x
    y <- stack.loss
    n <- length(y)
    p <- ncol(x)
    dyn.load(paste0("rqfn", .Platform$dynlib.ext))
    
    .Fortran("rqfn",
         as.integer(n),
         as.integer(p),
         a = as.double(t(as.matrix(x))),
         c = as.double(y),
         rhs = double(p),
         d = double(n),
         beta = as.double(0.99995),
         eps = as.double(1e-6),
         tau = as.double(0.5),
         wn = double(10 * n),
         wp = double((p + 3) * p),
         aa = double(p * p),
         it.count = integer(2),
         info = integer(1))
    
查看更多
登录 后发表回答