使用roxygen2框架,如何从另一个包中导入数据集,进行更改,然后将数据集重新导出为自己包中的数据集?
以我在导出数据集方面的经验,可以通过保存.rda文件(通常使用该save
函数)来手动完成此过程。我想使其更具动态性,因此,当人们更新依赖项包时,如果另一个包更新了数据集,则我的包将相应地更新其数据集。
例如,假设我stop_words
要从tidytext导入数据集,删除SMART
类型lexicon并重新导出为stop_words2
。有没有办法做到这一点?我将知道此解决方案何时data(package = 'MyPackage')
可以显示重新导出的数据集。
我的尝试无效(data(package =
即使可访问数据也无效):
#' Various lexicons for English stop words
#'
#' English stop words from three lexicons, as a data frame.
#' The onix sets are pulled from the tm package. Note
#' that words with non-ASCII characters have been removed. THis
#' is a reimport from the \pkg{tidytext} package's \code{stop_words}
#' data set but with the SMART lexicon filtered out.
#'
#' @format A data frame with 578 rows and 2 variables:
#' \describe{
#' \item{word}{An English word}
#' \item{lexicon}{The source of the stop word. Either "onix" or "snowball"}
#' }
#' @usage data(sam_i_am2)
#' @export
stop_words2 <- tidytext::stop_words[tidytext::stop_words[['lexicon']] != 'SMART', ]
我认为这是不可能的,因为data()
仅在子目录data/
中进行搜索,而子目录不在重新导出数据对象的位置。
但是,如果放弃此目标,则仍然可以像访问“延迟加载”数据集一样访问新数据对象。但请注意,使用不能正常工作data(stop_words2, package = "MyPackage")
。
#' Various lexicons for English stop words
#'
#' English stop words from three lexicons, as a data frame. The onix sets are
#' pulled from the tm package. Note that words with non-ASCII characters have
#' been removed. This is a reimport from the \pkg{tidytext} package's
#' \code{stop_words} data set but with the SMART lexicon filtered out.
#' @inherit tidytext::stop_words title description source references
#' @export
stop_words2 <- tidytext::stop_words[tidytext::stop_words[["lexicon"]] != "SMART", ]
请注意roxygen2对回收原始文档组件的使用。
考虑使用stopwords软件包,该软件包包含SMART单词以及更多内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句