不需要神秘的命名空间依赖项:"rlang"



此函数本身可以正确运行。当在R Studio中执行时,它打开View函数,窗口正确标记为mtcars(而不是df(:

#' Print a data frame appropriate to output type
#'
#' @param df the data frame to be printed
#'
#' @return either kable (in PDF) or datatable (in HTML) output
#' @importFrom DT datatable
#' @importFrom knitr kable
#' @importFrom utils View
#' @importFrom rlang enexprs
#' @export
#'
#' @examples # sp_print_df(df)
sp_print_df <- function(df){
df_name <- enexprs(df)
if (knitr::is_latex_output()) {
knitr::kable(df)(df)
}
else if (knitr::is_html_output()) {
DT::datatable(df)
}
else {
View(df, title = as.character(df_name[[1]]))
}
}
library(rlang)
sp_print_df(mtcars)

我在包中包含此函数时遇到了一些问题(https://github.com/smithjd/sqlpetr)。

当我在R Studio中执行devtools::check()时,.R文件中的@importFrom和包DESCRIPTION文件中rlang (>= 0.3.0.1),的各种排列(作为Imports:或作为Suggests(都会导致相同的错误消息:

❯ checking package dependencies ... ERROR
Namespace dependency not required: ‘rlang’
See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’
manual.
1 error ✖ | 0 warnings ✔ | 0 notes ✔
Error: R CMD check found ERRORs
Execution halted
Exited with status 1.

据我所知,roxygen包正在适当地生成NAMESPACE文件(这是一个片段(:

importFrom(purrr,map_chr)
importFrom(rlang,enexprs)
importFrom(stringr,str_detect)
importFrom(tibble,as_tibble)

关于"进口自",我缺少什么?或者这是Viewrlang的问题?

您必须将rlang包包含在DESCRIPTION文件的Imports部分(或Dependensmport(中。

函数中的">importFrom-rang enexprs"是正确的,不幸的是,除NAMESPACE文件外,DESCRIPTION文件不会自动更新,因此您必须手动将使用importFrom列出的所有包包含在描述文件中。

原来devtools::check((错误是sqlpetr中某个地方的ghost。R检查它在程序包目录旁边创建的文件夹。一旦发出错误消息,即使在我纠正了问题之后,它也不会消失。一旦我删除了那个目录,错误消息就消失了。

相关内容

最新更新