如何通过" @ importFrom"导入多个功能?在" .R"在R中的文件?

时间:2016-05-10 12:16:41

标签: r import package

我想在我的软件包中使用vars :: VAR和vars :: roots函数" .R" file(即StabilityPlot.R [VAR(p)的稳定性与p]相关;函数代码如下所示。

考虑到氧化,我该如何进行?

以下是我的想法:

#' @importFrom vars VAR roots

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

#' @importFrom(vars, roots, VAR)

我应该使用哪一个?或以上所有错误?任何线索? 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
}

1 个答案:

答案 0 :(得分:2)

前两个建议都应该有效。您可以看到roxygen2手册here的副本。第3页有你的问题的答案。

相关问题