pkgDep找不到我的包的依赖项

时间:2017-10-02 10:04:53

标签: r

我正在尝试将R包部署在具有依赖项的本地存储库中。

我的想法是与我公司的其他人共享此存储库,以便他们可以使用我的功能。他们还可以从本地存储库安装我的软件包依赖项,这比从CRAN下载它们更快并防止代理问题。

我正在使用miniCRAN和drat。

让我们从一个简单的例子开始:

我在RStudio中创建了一个新的@JsonValue public String toValue() { return value; } 包。

它只包含一个导入ggplot2的R文件(hello.R):

mytestpkg

我配置了项目选项,以便ROxygen生成NAMESPACE文件。这是它包含的内容:

#' Hello function
#'
#' @return NONE
#' @export
#' @import ggplot2
#'
#' @examples hello()
hello <- function() {
  print("Hello, world!")

  x <- seq(0, 10, by = 0.1)
  y <- cos(x)
  my.df <- data.frame(x, y)
  ggplot(my.df, aes(x, y)) + geom_line() + geom_point()
}

现在我将软件包安装在我的存储库中:

# Generated by roxygen2: do not edit by hand

export(hello)
import(ggplot2)

这里的问题是pkgList只包含一个字符串:

require(miniCRAN)
# Generate the documentation and update the NAMESPACE file
devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))
# Build the package
package.source.path <- devtools::build()
# Insert the package in my local repo
drat::insertPackage(package.source.path,
                    repodir = "C:/path/to/my/repo",
                    action = "prune")
# Add my local repo to the list of repos
options(repos = c(CRAN = "https://ftp.igh.cnrs.fr/pub/CRAN/",
                  MyRepo = "file:///C:/path/to/my/repo"))
# Find dependencies
pkgs <- c("mytestpkg")
pkgList <- pkgDep(pkgs, type="source")

因此,如果我调用makeRepo,它只会复制我的包而不是它的依赖项。

我做错了什么?

编辑:

显然,depPkg会查找DESCRIPTION文件中的导入,而不是NAMESPACE文件。

因此,每次进行新导入时,我都需要手动编辑DESCRIPTION文件? 这很不方便...... Roxygen不能这样做吗?

1 个答案:

答案 0 :(得分:1)

要指定包依赖关系,可以使用:

devtools::use_package("ggplot2")

然后它会自动添加到您的DESCRIPTION文件中。

相关问题