我尝试构建一个使用库tidyverse
的R包。
描述文件如下:
Package: myFirstPackage
Title: A initial package
Version: 0.0.1.0
Authors@R:
person(given = "Test",
family = "Test",
role = c("aut", "cre"),
email = "first.last@example.com",
comment = c(ORCID = "YOUR-ORCID-ID"))
Description: a description.
Imports: tidyverse
License: GPL-2
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
所以我将tidyverse
添加到Imports
部分。
我的R代码如下:
myfunction<-function(){
x<-tibble(
id = c(1, 2, 3, 4),
name = c("Louisa", "Jonathan", "Luigi", "Rachel"),
female = c(TRUE, FALSE, FALSE, TRUE)
)
x %>% pull(id)
}
#' MyDemoFunction
#'
#'
#' @import tidyverse
#' @export
say_hello<-function(){
cat("here1")
myfunction()
}
在这里,我有导入。
我正在使用R-Studio工作,一旦我按下“检查”按钮,我会得到以下结果:
> checking R code for possible problems ... NOTE
myfunction: no visible global function definition for 'tibble'
myfunction: no visible global function definition for '%>%'
myfunction: no visible global function definition for 'pull'
myfunction: no visible binding for global variable 'id'
Undefined global functions or variables:
%>% id pull tibble
你可以在这里找到该项目的存储库。
在那个问题中,通过逐个导入函数来解决了问题,但我希望完全导入整个包:我只想使用tidyverse的所有函数,而不需要显式定义每个函数。在这个问题中提到,导入必须在描述中完成,而我已经做到了!