包装开发:如何从包装中导入数据,对其进行转换并将其导出为数据集?

问题描述 投票:3回答:1

使用roxygen2框架,如何从另一个包中导入数据集,进行更改,然后将数据集重新导出为我自己的包中的数据集?

根据我在导出数据集方面的经验,可以通过保存.rda文件(通常使用save函数)来手动完成此过程。我想让它更具动态性,因此,当人们更新依赖项包时,如果另一个包更新了数据集,我的包将相应地更新其数据集。

例如,假设我要从tidytext导入stop_words数据集,删除SMART类型的词典,然后重新导出为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', ]
r roxygen2
1个回答
0
投票

我不认为这是可能的,因为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 package,其中包含SMART单词以及更多内容。

© www.soinside.com 2019 - 2024. All rights reserved.