Extracting a data.frame of parameters values for an xml file or a set of (whatever the xml file kind)

get_xml_files_param_df(file_path, param_names = NULL, wide_shape = FALSE)

Arguments

file_path

A file path or a vector of STICS XML files

param_names

vector of parameters names (optional)

wide_shape

Optional logical for keeping the long data.frame format FALSE, default) or converting it to a wider format one (TRUE), with parameters as columns

Value

A single long data.frame with name, type, param, id and value columns, value is of type character. or a wide a data.frame with name, type, and all other columns correspond to parameter names, with indices as suffix for multiple values (as in _tec.xml files for water supply, N supply, ...)

Details

An extract of returned data.frames with the 2 formats from an usms.xml file as input

  • Default data.frame long format

nametypeparamidvalue
SugarCaneusmsdatedebutNA286
SugarCaneusmsdatefinNA650
SugarCaneusmsfinitNAcanne_ini.xml
SugarCaneusmsnomsolNAsolcanne
SugarCaneusmsfstationNAclimcanj_sta.xml
...............
...............
param_gen.xmlfichierparQmulchdec170
param_gen.xmlfichierparQmulchdec180
param_gen.xmlfichierparQmulchdec190
param_gen.xmlfichierparQmulchdec200
param_gen.xmlfichierparQmulchdec210

name: a file name or an usm or soil name type: type of file param: param name id: NA for scalar, integer id for vectors parameters value: parameter value

  • wide data.frame format

nametypedatedebutdatefinfinitnomsol
SugarCaneusms286650canne_ini.xmlsolcanne
potatousms91250patate_ini.xmlsolpatate
bananausms30300banane_ini.xmlsolbanane
sorghumusms112360sorgho_ini.xmlsolsorgho
barleyusms88196orge_ini.xmlsolorge

name: a file name or an usm or soil name type: type of file all other columns names correspond to parameter names, with indices as suffix for multiple values (as in _tec.xml files)

Examples

if (FALSE) { # \dontrun{
dir_path <- get_examples_path("xml")

get_xml_files_param_df(
  file_path = file.path(dir_path, "sols.xml")
)

files_list <- file.path(dir_path, c("sols.xml", "usms.xml", "param_gen.xml"))
# long format (default)
get_xml_files_param_df(file_path = files_list)

# wide format
get_xml_files_param_df(file_path = files_list, wide_shape = TRUE)
} # }