读取和使用自定义配置文件 [英] Reading and using a custom configuration file

查看:62
本文介绍了读取和使用自定义配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在处理一个脚本,该脚本应该基于配置"文件来分析数据集.

I'm currently working on a script which should analyze a dataset based on a 'configuration' file.

此文件的输入例如:

configuration.txt:

configuration.txt:

123456, 654321
409,255,265
1

它也可以包含其他值,但是它们都是数字.在上述示例中,应按以下方式读取文件:

It can contain onther values as well, but they will al be numeric. In the example described above the file should be read in as follows:

timestart <- 123456
timeend <- 654321
exclude <- c(409,255,265)
paid <- 1

配置文件的布局不是固定的,但它应包含一个开始时间(unix),结束时间(unix)一个数组,其中包含要排除的数字和其他字段.最后,它应该由用户在GUI中指定的字段构造.我不知道哪种格式最适合这种情况,但是一旦这些基本知识起作用,我认为这不会成为大问题.

The layout of the configuration file is not fixed, but it should contain a starting time (unix) an ending time (unix) an array with numbers to exclude and other fields. In the end it should be constructed from fields a user specifies in a GUI. I don't know which formatting would suit best for that case, but as soon as I have these basics working I don't think that will be a big problem.

但是,这将使得更难知道哪些值属于哪个变量.

But that will make it harder to know which values belong to which variable.

推荐答案

确实,如Andrie所建议的那样,使用.r配置文件是最简单的方法.我完全忽略了该选项!

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

因此,只需创建一个.r文件,其中已包含变量:

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

在其他脚本中使用:

source("config.R")

瞧.谢谢安德里!

这篇关于读取和使用自定义配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆