程序包开发:如何从程序包导入数据,对其进行转换并将rexport作为数据集?

泰勒·林克

使用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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何导入/调用程序包的“子程序包”?

如何从我的程序包中的另一个程序包加载数据

开发和调试Atom程序包

VSCode:无法导入Golang程序包

Scala:程序包导入冲突

无法导入Imagick程序包

定义程序包范围的默认导入

试图了解如何通过webpack导入Web程序包

如何导入官方的mongodb驱动程序包

如何在导入的程序包中引用函数?

如何从SQL Server Integration Services目录导入程序包?

流星-用于拖放数据更改的程序包

如何限制特定的程序包/软件进行更新\升级?

如何对golang标准库的程序包进行基准测试?

如何创建Java程序包以及如何在另一个程序包中导入它们?

导入模块(或程序包).function实际上会导入整个模块/程序包吗?

木偶:无需其他程序包即可覆盖API请求并使用模拟数据进行响应

使用Hibernate程序包从另一个程序包访问数据库

导入自定义程序包显示“错误:程序包com不存在”

导入Postgresql程序包时工作程序包失灵

创建的程序包未运行NAMESPACE文件中导入的程序包的功能

从〜运行程序包如何工作?

如何从应用程序包中的文件中读取数据 I macOS?

如何在多个程序包之间共享单个数据库连接

如何使func main()中设置的数据库实例可用于其他程序包?

Java程序包是否等效于.Net程序集?

.NET分析工具:程序包版本与程序集版本

节点程序包与浏览器程序包

程序包与同名的现有程序包冲突