我有一个包,其中包含一个函数,该函数从fread调用data.table。data.table在其描述文件的建议字段中包含了bit64包,这使fread能够以integer64而不是numeric的形式导入大整数。在我的包中,默认情况下,我需要这个功能。
下面是一个可重复的例子,在R3.1.3下(早期版本没有这个问题)。
尝试1
Vectorize(dir.create)(c("test", "test/R", "test/man"))
cat(
"Package: test
Title: Test pkg
Description: Investigate how to use suggested package
Version: 0.0-1
Date: 2015-03-10
Author: Richie Cotton
Maintainer: Richie Cotton <a@b.com>
Imports: data.table
Suggests: bit64
License: Unlimited
",
file = "test/DESCRIPTION"
)
cat(
"#' Read data
#'
#' Wrapper to \\code{fread} that loads bit64 first
#' @param ... Passed to fread.
#' @return A data frame of uniformly distributed random numbers and their index.
#' @importFrom data.table fread
#' @export
read_data <- function(...)
{
library(bit64)
fread(...)
}",
file = "test/R/read_data.R"
)当我运行R CMD check时
library(roxygen2)
library(devtools)
roxygenize("test")
check("test")我得到以下NOTE
* checking dependencies in R code ... NOTE
'library' or 'require' call to 'bit64' in package code.
Please use :: or requireNamespace() instead.
See section 'Suggested packages' in the 'Writing R Extensions' manual.企图2
文档建议用requireNamespace代替library。这将检查包是否存在,但不会将其加载到R的搜索路径。
如果我将read_data的定义更新为:
read_data <- function(...)
{
if(!requireNamespace('bit64'))
{
warning('bit64 not available.')
}
fread(...)
}然后R CMD check运行得很平稳,但是由于bit64现在没有加载,所以fread无法读取长整数。
尝试3
如果我将DESCRIPTION更改为使bit64位于Depends部分(而不是Suggests ),并将read_data保持在第2次尝试中,或者将其简化为
read_data <- function(...)
{
fread(...)
}然后R CMD check给出了NOTE
* checking dependencies in R code ... NOTE
Package in Depends field not imported from: 'bit64'
These packages need to be imported from (in the NAMESPACE file)
for when this namespace is loaded but not attached.我不太确定在这种情况下我应该进口什么。
企图4
如果我将bit64保留在Depends部分,并使用read_data的原始定义,
read_data <- function(...)
{
library(bit64)
fread(...)
}然后R CMD check给出了NOTE
* checking dependencies in R code ... NOTE
'library' or 'require' call to 'bit64' which was already attached by Depends.
Please remove these calls from your code.
Package in Depends field not imported from: 'bit64'我觉得应该有一些DESCRIPTION和函数定义的神奇组合,它给了我bit64的功能,并且干净地传递了R CMD check;我只是看不出我错过了什么。
我该怎么做?
发布于 2015-03-10 11:55:23
第3次尝试是最近的;我只是在roxygen文档中需要一个额外的@import bit64。
Vectorize(dir.create)(c("test", "test/R", "test/man"))
cat(
"Package: test
Title: Test pkg
Description: Investigate how to use suggested package
Version: 0.0-1
Date: 2015-03-10
Author: Richie Cotton
Maintainer: Richie Cotton <a@b.com>
Depends: bit64
Imports: data.table
License: Unlimited
",
file = "test/DESCRIPTION"
)
cat(
"#' Read data
#'
#' Wrapper to \\code{fread} that loads bit64 first
#' @param ... Passed to fread.
#' @return A data frame of uniformly distributed random numbers and their index.
#' @import bit64
#' @importFrom data.table fread
#' @export
read_data <- function(...)
{
fread(...)
}",
file = "test/R/read_data.R"
)https://stackoverflow.com/questions/28961735
复制相似问题