【问题标题】:How to import more than 1 function via "@importFrom" in an ".R" file in R?如何在 R 中的“.R”文件中通过“@importFrom”导入多个函数?
【发布时间】:2016-09-05 10:01:47
【问题描述】:

我想在我的包的“.R”文件中使用 vars::VAR 和 vars::roots 函数(即 StabilityPlot.R [Stability of VAR(p) accross p];函数代码如下)。

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

我想到了以下几点:

#' @importFrom vars VAR roots

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

#' @importFrom(vars, roots, VAR)

我应该使用哪一个?还是以上都错了?有什么线索吗?谢谢。

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
}

【问题讨论】:

  • 两个单独的 importFrom 工作(上面的第二个选项)。我问了这个问题,因为我找不到 importFrom 的语法。在控制台中,>importFrom 产生“错误:找不到对象'importFrom'”; >@importFrom 产生“错误:“@”中的意外'@'。

标签: r import package


【解决方案1】:

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

【讨论】:

  • 非常感谢。看来我在错误的地方搜索了语法(“Writing R extensions...”)。
  • 没问题,乐于助人
  • 链接已失效。
猜你喜欢
  • 2015-09-01
  • 1970-01-01
  • 2021-10-25
  • 1970-01-01
  • 1970-01-01
  • 2018-11-22
  • 2017-10-24
  • 1970-01-01
  • 2017-01-18
相关资源
最近更新 更多