我建立了一个R包(SemNetDictionaries),其中包含一些包含不同词典词汇表的数据。我想为用户提供一个选项,以覆盖这些词典,因为它们将它们与软件包的基本词典中未包含的响应一起使用。是否可以允许用户直接将数据附加到R包中?
用户已经可以创建自己的独立词典(可以将其保存到计算机中)
我已经弄清楚了如何使用tools ::: makeLazyLoadDB;但是,在为CRAN构建程序包时(这是一个内部功能),这会引发一些警告,并且会损坏程序包。
# Load R package
library(SemNetDictionaries)
# Loads the "animals" dictionary in package
base <- SemNetDictionaries::load.dictionaries("animals")
# Word to add to dictionary in package
word2add <- "bluebird"
# Get data file names in package
data.files <- data(package="SemNetDictionaries")$results[,"Item"]
# Load data in package
lazyLoad(paste(system.file("data",package="SemNetDictionaries"),"Rdata",sep="/"))
# Update dictionary
.GlobalEnv[["animals.dictionary"]] <- unique(sort(c(base, word2add)))
# Remove all objects in the environment except for updated dictionary
rm(list = setdiff(ls(),data.files))
# Save data to package
tools:::makeLazyLoadDB(.GlobalEnv, paste(system.file("data",package="SemNetDictionaries"),"Rdata",sep="/"))
# Load dictionaries again (words are updated)
SemNetDictionaries::load.dictionaries("animals")
# This, however, corrupts the R package (see error below)
Error in get(data(list = dict.long, envir = environment())) :
lazy-load database 'C:\Users\apchrist\Documents\R\win-library\3.6\SemNetDictionaries/data/Rdata.rdb' is corrupt
In addition: Warning message:
In get(data(list = dict.long, envir = environment())) :
internal error -3 in R_decompress1