Using .Fortran() from R package with error saying function not available

◇◆丶佛笑我妖孽 提交于 2020-01-24 00:55:14

问题


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:


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))
    


来源:https://stackoverflow.com/questions/48293309/using-fortran-from-r-package-with-error-saying-function-not-available

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!