fread.msproj {MSDem} | R Documentation |
fread.msproj
is a convenience function that can be used to read all the files generated by the state.space
function and bring it into the list form required by msproj
.
fread.msproj(data.dir = "input_data/", model.patt = NULL)
data.dir |
The path to the directory that contains the data sets. Defaults to the subdirectory "input_data/" of the current working directory. If the user wants to use a different directory, he has to specify the whole path instead. |
model.patt |
The name of the scenario as contained in the names of all relevant data sets. |
Using this function requires that all the relevant files (state space, variable defintions, and possibly migration) are contained in the same folder and show the same pattern in their names. This is guaranteed if the state.space
function was used to create these files and the user didn't make any manual changes. If a user really wants to rename the files, it is only possible to do this for the parts specifying the country and the scenario, respectively, but the patterns "_mig", "_state_space", and "_var_def" must be kept in the naming!
fread.msproj
returns a list consisting of three elements if migration is considered or two elements otherwise:
state.space |
A data frame containing the state space itself. It contains all the data needed to run the simulation (population, fertility, mortality etc.) for all possible combinations of sex, age, region etc. There is only one exception: Migration data has a different structure and thus, is written into a separate list element. |
variable.definitions |
A two-dimensional vector containing an overview of the variables used in the simulation and the values they may take. This information is partly used in the simulation itself, but also can be seen as metadata that provides useful information about the specific simulation settings. |
migration |
A data frame containing the flows of migration for each possible combination of origin and destination. Only created when migration is part of the model. |
Every list element represents one of the files that have been read. Hence, where state.space
split up the list that it created and saved the list elements as single files to a certain directory, fread.msproj
does just the opposite. When comparing the lists, the only difference is the matrix of education transitions that is created by state.space
, but not save to a file, and thus, not included in the list created by fread.msproj
.
Marcus Wurzer
The function is based on the fread
function included in the data table package.
## Creating a state space for India and giving this scenario a name: st.sp <- state.space(country = "India", scen = "test_scenario") str(st.sp) ## Reading the files that have been saved to the current ## working directory automatically. The pattern consists of ## the country name and the name of the scenario, separated ## by an underscore: datasets <- fread.msproj(model.patt = "India_test_scenario") str(datasets)