【发布时间】:2019-05-02 02:31:17
【问题描述】:
我有一个“测试”包,其中数据对象“test_data”保存在文件名为“test_data.RData”的数据文件夹中。
测试包含一个使用该数据对象的函数 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()
}
我在说明的导入部分进行了测试,但失败了。
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 有关系吗?
可能是this question的副本
【问题讨论】:
标签: r namespaces package