Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

50 lines (38 sloc) 2.544 kB

Description

This program helps users to create a list to hold user-supplied parameters and export it to an external file in JSON format.

It is inspired by a post by Iterator on stackoverflow:

It aims at "saving parameters that differ between sets/runs/experiments in an external parameter files". So to run or repeat those experiments, we just need to source the parameters and the operations will be automatically determined. Check here for the script.

Example

We will use the parameters in the post as an example. Suppose we want to configure the following parameters:

{
 "Version": "20110701a",
 "Initialization":
 {
   "indices": [1,2,3,4,5,6,7,8,9,10],
   "step_size": 0.05
 },
 "Stopping":
 {
   "tolerance": 0.01,
   "iterations": 100
 }
}

We can, of course, manually create it and save it somewhere. Or we can use the following script (It requires the RJSONIO package).

source("parameter_configuration.R") # the file path depends on your current work directory
ParamConfiguration() # load the parameter configuration function

The current working directory will be printed out first and several prompts will show up asking for file name to save the parameters and its containing directory. alt tag

The parameter configuration begins and you are free to set any parameter as you want. There are 2 types of parameters:

  • Single parameters, like "Version" since it does not take nested parameters as their value.
  • Group parameters, like "Initialization" and "Stopping".

For each parameter, the script will guide you through to specify its type, name and value. The VALUE must follow the grammer of R. For example, to enter the value for Version, type "20110701a" with the double quote.

The script will print out the parameter list to the console so you can check if they match with your intention. alt tag

In the JSON file, we have the following content. All values are treated as arrays in JSON regardless of the length of its original form in R. This ensures that when this JSON file is read into R, the list generated will have the same structure as shown in the figure above. alt tag

To read the params back in, use the fromJSON() from the RJSONIO package. alt tag

Jump to Line
Something went wrong with that request. Please try again.