从软件包中的sysdata.rda自动加载数据 [英] Automatic loading of data from sysdata.rda in package
问题描述
我花了很多时间来寻找可能是一个非常基本的问题的答案,但我只是找不到解决问题的方法.我找到的最接近的是此交换来自几年前.
I have spent a lot of time searching for an answer to what is probably a very basic question, but I just can't find the solution to my issue. The closest that I found was this exchange from a few years ago.
在这种情况下,问题在于sysdata.rda文件在软件包内正确目录中的位置.那不是我的问题.
In that case, the issue was the location of the sysdata.rda file in the correct directory within the package. That is not my issue.
我有一些变量,用于存储诸如包装内有趣的调色板之类的东西.这些变量仅在函数内部使用,因此我将它们存储在R/sysdata.rda中.但是,当我加载软件包时,变量没有加载到软件包环境中.如果我从sysdata.rda手动加载数据,则一切正常.
I have some variables that store things like color palettes that I amusing inside a package. These variables are only used inside my functions so I storing them in R/sysdata.rda. However, when I load the packages, the variables are not loading into the package environment. If I load the data manually from sysdata.rda then everything works fine.
通过阅读我可以在R包中的内部数据上找到的所有内容后,我的印象是R/sysdata.rda中的数据将自动加载.
My impression from reading everything that I could find on internal data in R packages was that the data in R/sysdata.rda would load automatically.
这是我用来存储数据的代码.
Here is the code that I am using to store my data.
devtools::use_data(tmpBrks, tmpColors, prcpBrks, prcpChgBrks,
prcpChgBrkLabels, prcpColors, prcpChgColors,
internal = TRUE, overwrite = TRUE)
那将在R/sysdata.rda上成功创建数据文件,并且当我手动加载数据时该数据就在文件中.
That successfully creates the data file at R/sysdata.rda and the data is in the file when I load it manually.
我需要怎么做才能自动加载数据,以便程序包中的功能可以使用它们?
What do I need to do to have the data load automatically so the functions in my package can use them?
推荐答案
像往常一样,这是用户无知和不良R文档的不良组合.数据已被加载,并且可供功能使用.我出错的地方是假设数据在包环境中是可见的.事实并非如此.
As usual, this was a bad combination of user ignorance and poor R documentation. The data was being loaded and was available to the functions. Where I went wrong was in assuming that the data would be visible in the package environment. That is not the case.
据我所知,R \ sysdata.rda文件中的内部数据可用于程序包中的功能,但不能以任何方式看到.创建内部数据文件后,我正在包环境中查找数据.当我没有看到它时,我以为它没有被加载.当我继续进行软件包开发时,我终于意识到数据正在以静默方式加载,并且可以被软件包中的功能访问.
As far as I can tell, internal data in the R\sysdata.rda file is available to the functions within the package, but not visible in any way. After I created the internal data file I was looking for the data in the package environment. When I didn't see it I assumed that it wasn't loaded. When I kept pushing forward with my package development I finally realized that the data was loading silently and accessible to the functions in the package.
正如我的问题得到的两次投票所证明的那样,我不是唯一一个不了解R \ sysdata.rda内部数据的行为的人.希望这种解释将为其他人节省大量时间来寻找该问题的答案,而这个问题并不存在.
As evidenced by the two up votes that my question got, I am not the only one who didn't understand the behavior of the R\sysdata.rda internal data. Hopefully this explanation will save someone else a bunch of time searching for an answer to this issue that doesn't really exist.
这篇关于从软件包中的sysdata.rda自动加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!