Search code examples
rfortranquantreg

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


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.


Solution

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