【发布时间】:2017-10-02 10:04:52
【问题描述】:
我正在尝试将我的 R 包部署到本地存储库及其依赖项。
我们的想法是与我公司的其他人共享此存储库,以便他们可以使用我的功能。他们还可以从本地存储库安装我的包依赖项,这比从 CRAN 下载它们要快,并且可以防止代理问题。
我正在为此使用 miniCRAN 和 drat。
让我们从一个简单的例子开始:
我在 RStudio 中创建了一个新的 mytestpkg 包。
它只包含一个导入ggplot2的R文件(hello.R):
#' 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()
}
我配置了项目选项,以便 ROxygen 生成 NAMESPACE 文件。以下是它包含的内容:
# Generated by roxygen2: do not edit by hand
export(hello)
import(ggplot2)
现在我将包安装到我的存储库中:
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")
这里的问题是 pkgList 只包含一个字符串:
> pkgList
[1] "mytestpkg"
所以如果我调用 makeRepo,它只会复制我的包而不是它的依赖项。
我做错了什么?
编辑:
显然,depPkg 查找的是DESCRIPTION文件中的导入,而不是NAMESPACE文件。
所以每次我有新的导入时,我都需要手动编辑DESCRIPTION文件吗? 这很不方便...... Roxygen 不能这样做吗?
【问题讨论】:
标签: r