如何在不使用库(pkg)的情况下修复“没有项目名称”包:pkg“在搜索列表中?”

时间:2015-07-23 13:53:30

标签: r debugging

我正在编写一个名为testpkg的软件包,并将quantmod放在DESCRIPTION文件的Depends部分。

我写了以下功能:

#' hello1
#'
#' @return NA
#' @export
hello1 <- function() {
  print("hello1!")
  quantmod::is.HLC("Hello, world!")
}

#' hello2
#'
#' @return NA
#' @export
hello2 <- function () {

    x <- structure(c(25.85, 25.639999, 26.700001, 26.26, 26.92, 27.870001,
                   25.26, 25.52, 26.66, 25.610001, 26.85, 27.74, 26352700, 32512200,
                   64264600, 25.610001, 26.85, 27.74),
                 .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC",
                 src = "yahoo", updated = structure(1437653990.9303, class = c("POSIXct",
                                                                               "POSIXt")),
                 class = c("xts", "zoo"), index = structure(c(1167782400,
                                                              1167868800, 1167955200),
                                                            tzone = "UTC",
                                                            tclass = "Date"),
                 .Dim = c(3L, 6L), .Dimnames = list(NULL, c("YHOO.Open", "YHOO.High", "YHOO.Low",
                                                            "YHOO.Close", "YHOO.Volume", "YHOO.Adjusted")))
    print(x)
    quantmod::chartSeries(x)

}

现在,当我进入项目并运行testpkg::hello1()时,我得到了我期望的输出。

但是,如果我运行testpkg::hello2(),我会看到x已打印,但未生成图表。我收到错误:

Error in as.environment("package:quantmod") : 
  no item called "package:quantmod" on the search list

我知道我可以在致电library(quantmod)之前致电testpkg::hello2()来解决此问题,但我觉得testpkg::hello1()可以无需调用library(quantmod)就可以无错运行。这是什么原因,是否有另一种方法可以在不先调用testpkg::hello2()的情况下运行library(quantmod)

0 个答案:

没有答案