R package: writing internal data, but not all at once

早过忘川 提交于 2019-12-10 16:01:33

问题


I'm working on an R package using usethis/devtools. The package has a few objects I'd like to keep internal, just to keep down the clutter. The structure I was using was to make objects in different files based on their source, all in my data-raw folder. For instance, the file make_laus_codes.R preps two data frames of lookup codes from the Bureau of Labor Statistics (one internal, called laus_codes), and the file make_decennial_tables.R preps lookup codes from the Decennial Census (including an internal, decennial_nums).

If I make a call like usethis::use_data(data_name, internal = TRUE), I get an error if the sysdata.rda file has already been created and I haven't chosen to overwrite it; if I choose to overwrite, it overwrites the whole thing, rather than what I'd expected, which is appending the second object to sysdata.rda.

The accepted answer to Store multiple objects in sysdata.rda: R-package development says to call usethis::use_data(laus_codes, decennial_nums, internal = TRUE), but a comment there poses the question of what if these objects aren't being created at the same time, and that's where I'd like to pick up.

A simplified version of my structure is as follows:

data-raw/make_laus_codes.R:

laus_codes <- data.frame(
  area = c("Connecticut", "Fairfield County", "Hartford County"),
  code = c("ST0900000000000", "CN0900100000000", "CN0900300000000")
)

data-raw/make_decennial_tables.R:

decennial_nums <- c("H002", "H003", "H004", "H005", "H006")

data-raw/make_internal_data.R:

source("./make_laus_codes.R")
source("./make_decennial_tables.R")

usethis::use_data(laus_codes, decennial_nums, internal = TRUE)

This works, but it feels awkward and like I'm missing the intended way to do this. Is there a way to do this that is better, more proper, and/or intended by usethis? It feels susceptible to bugs and forgetfulness to be sourcing other files this way.

来源:https://stackoverflow.com/questions/51384397/r-package-writing-internal-data-but-not-all-at-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!