我有一个名为“testing”的包,其中包含一个名为“test_data”的数据对象,保存在文件夹"data"下,文件名为"test_data.RData"。
testing包中包含一个函数hello(),该函数使用此数据对象。
以下代码可以正常工作:
但是这个失败了:
如果它是一个函数而不是数据对象,那么导入功能就可以正常运行,为什么用数据对象时不同,我需要加载已导入的包吗?我错过了些什么吗?这与LazyData和LazyLoad有关吗?
可能是这个问题的重复。
testing包中包含一个函数hello(),该函数使用此数据对象。
#' hello
#'
#' @return Prints hello "your_name"
#' @export
#'
#' @examples
#' hello()
hello <- function(your_name = "") {
print(paste("test_data has", nrow(test_data), "rows"))
print(sprintf("Hello %s!", your_name))
}
以下代码可以正常工作:
require(testing)
testing::hello()
[1] "test_data has 32 rows"
[1] "Hello !"
但是这个失败了:
testing::hello()
Error in nrow(test_data) : object 'test_data' not found
实际上我并没有直接使用它,而是在另一个引用了这个函数的包testingtop中使用:
#' Title
#'
#' @export
#' @importFrom testing hello
hello2 <- function(){
hello()
}
我在DESCRIPTION文件的Imports部分进行测试,但是测试失败了。
require(testingtop)
testingtop::hello2()
Error in nrow(test_data) : object 'test_data' not found
如果我将其放在Depends中,如果我使用library()加载包,则它可以正常工作,否则仍然会失败:
> library(testingtop)
Loading required package: testing
> testingtop::hello2()
[1] "test_data has 32 rows"
[1] "Hello !"
Restarting R session...
> testingtop::hello2()
Error in nrow(test_data) : object 'test_data' not found
如果它是一个函数而不是数据对象,那么导入功能就可以正常运行,为什么用数据对象时不同,我需要加载已导入的包吗?我错过了些什么吗?这与LazyData和LazyLoad有关吗?
可能是这个问题的重复。