Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import more than 1 function via "@importFrom" in an ".R" file in R?

Tags:

import

package

r

I want to use vars::VAR and vars::roots functions in my package's ".R" file (i.e., StabilityPlot.R [Stability of VAR(p) accross p]; the function code is below).

With roxygenization in consideration, how can I perform this?

The followings come into my mind:

#' @importFrom vars VAR roots

or

#' @importFrom vars VAR 
#' @importFrom vars roots

or

#' @importFrom(vars, roots, VAR)

Which one should I use? Or all the above wrong? Any clue? Thx.

StabilityPlot <- function(data, p=5, type = c("const","trend","both","none"))
{
out <- list()
data <- as.data.frame(data)
maxmodulusofinverseroots <- matrix(, nrow = p, ncol =1)
#........................................................................
if (type==c("const")) { 
maxmodulusofinverseroots[,1] <- matrix(unlist(lapply(as.matrix(1:p),function(x){max(roots(VAR(mydata, p=x, type = "const"), modulus=TRUE))})), ncol=1)
}
if (type==c("trend")) { 
maxmodulusofinverseroots[,1] <- matrix(unlist(lapply(as.matrix(1:p),function(x){max(roots(VAR(mydata, p=x, type = "trend"), modulus=TRUE))})), ncol=1)
}
if (type==c("both")) { 
maxmodulusofinverseroots[,1] <- matrix(unlist(lapply(as.matrix(1:p),function(x){max(roots(VAR(mydata, p=x, type = "both"), modulus=TRUE))})), ncol=1)
}
if (type==c("none")) { 
maxmodulusofinverseroots[,1] <- matrix(unlist(lapply(as.matrix(1:p),function(x){max(roots(VAR(mydata, p=x, type = "both"), modulus=TRUE))})), ncol=1)
}
out$maxmoduluses <- maxmodulusofinverseroots
#........................................................................
if (type==c("const")) {
plot(ts(maxmodulusofinverseroots), plot.type="single", xlab="p (order of VAR)", main="Stability of VAR(p) accross p; det.regr:const", ylab="MaxModOfInvRootsOfARchrPoly", col=c("black"), lty=1:2)
}
if (type==c("trend")) {
plot(ts(maxmodulusofinverseroots), plot.type="single", xlab="p (order of VAR)", main="Stability of VAR(p) accross p; det.regr:trend", ylab="MaxModOfInvRootsOfARchrPoly", col=c("black"), lty=1:2)
}
if (type==c("both")) {
plot(ts(maxmodulusofinverseroots), plot.type="single", xlab="p (order of VAR)", main="Stability of VAR(p) accross p; det.regr:both", ylab="MaxModOfInvRootsOfARchrPoly", col=c("black"), lty=1:2)
}
if (type==c("none")) {
plot(ts(maxmodulusofinverseroots), plot.type="single", xlab="p (order of VAR)", main="Stability of VAR(p) accross p; det.regr:none", ylab="MaxModOfInvRootsOfARchrPoly", col=c("black"), lty=1:2)
}
abline(1,0)
out
}
like image 262
Erdogan CEVHER Avatar asked Sep 06 '25 03:09

Erdogan CEVHER


1 Answers

Both of your first two suggestions should work. You can see a copy of the roxygen2 manual here. Page 3 has the answer to your question.

like image 162
jamieRowen Avatar answered Sep 08 '25 20:09

jamieRowen