Reading and using a custom configuration file

你离开我真会死。 提交于 2019-12-03 02:08:39

Indeed, as Andrie suggested, using a .r config file is the easiest way to do it. I overlooked that option completely!

Thus, just make a .r file with the variables already in it:

#file:config.R
timestart <- 123456
timeend <- 654321
exclude <- c(409,255,265)
paid <- 1

In other script use:

source("config.R")

And voila. Thank you Andrie!

Another alternative would be to use the config package. This allows setting configuration values to be executed according to the running environment (production, test, etc.). All parameters are accessed by a list and are loaded by a YAML text format configuration file.

More details and examples about config can be found here: https://cran.r-project.org/web/packages/config/vignettes/introduction.html

If you wants to load a JSON, TOML, YAML, or INI text configuration file, see also the configr package.

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