Closed Chabrier closed 1 year ago
An unexported function can do this, and may be also used for generating csv files for every kind of file usms, tec, ini, ... 2 data.frame output format can be produced a wide (as in excel files used for generating xml files) or a long format. It works on a list of xml files, so parameters can be extracted for a whole JavaStics workspace
SticsRFiles:::get_xml_files_param_df(file_path = "usms.xml", wide_shape = TRUE)
# A tibble: 43 × 20 name type dated…¹ datefin finit nomsol fstat…² fclim1 fclim2 cultu…³ nbpla…⁴ codes…⁵ fplt_11 SugarC… usms 286 650 cann… solca… climca… climc… climc… 0 1 0 proto… 2 potato usms 91 250 pata… solpa… climpd… climp… climp… 1 1 0 proto… 3 banana usms 30 300 bana… solba… climba… climb… climb… 1 1 0 proto… 4 sorghum usms 112 360 sorg… solso… climso… clims… clims… 1 1 0 proto… 5 sugarb… usms 1 335 bett… solbe… climbe… climb… climb… 1 1 0 sugar…
xml_files <- list.files(path = "JavaSTICS-1.42-stics-v10/example",pattern = "\\.xml$", full.names = TRUE)
SticsRFiles:::get_xml_files_param_df(file_path = xml_files, wide_shape = TRUE)
<pre>
# A tibble: 182 × 1,052
name type julres coderes qres Crespc CsurN…¹ Nminres eaures code_…² resk resz jultrav profres proft…³ iplt0 profsem densi…⁴
<chr> <chr> <int> <int> <dbl> <int> <int> <int> <int> <int> <dbl> <int> <int> <int> <int> <int> <dbl> <dbl>
1 aiadan4_tec… fich… 70 1 2.33 42 80 0 0 1 0.14 5 70 0 20 77 4 200
2 AuzevilleJ_… fich… NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
3 banane_ini.… init… NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
4 banane_tec.… fich… 30 1 4 42 40 0 0 1 0.14 5 30 0 20 32 20 0.18
5 bettera_ini… init… NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
</pre>
Guess it will help.
Patrice.
Excellent, il will help, yes!
Very interesting when you have to develop an experimental plan.
Just wondering, why this is not exported?
Anyway, thanks for the feedback.
I went farther, but when working either with tec or init files i get some issues that i share here, with this code.
library(SticsRFiles)
library(dplyr)
javasticsPath <- "/home/pchabrier/DEVS/playingWithSticsR/distrib/JavaSTICS-1.5.1-STICS-10.0.0"
exampleXmlPath <- file.path(javasticsPath,"example")
exampleTecFile <- file.path(exampleXmlPath, "ble1_tec.xml")
# getting all the parameters
ble1_Tec <- SticsRFiles:::get_xml_files_param_df(file_path = exampleTecFile, wide_shape = TRUE)
# removing the type column and renaming the name column
ble1_Tec_T <- rename(ble1_Tec, Tec_name = name) %>% select(-type)
# now expecting to recreate the xml file
# this does not work, the error message is curious
# Unknown parameters found in table: julapN_or_sum_upvt_or_sum_upvt
# But one of the reason could be that the default template file is not compatible with
# ble1_tec.xml
gen_tec_xml(out_dir = getwd(), param_df = ble1_Tec_T)
# this does not work either, and in this case, we could expect get the same file,
# since we take as template the file from where the parameters comes
gen_tec_xml(out_dir = getwd(), param_df = ble1_Tec_T, file = exampleTecFile)
# on a subset of parameters it does work
ble1_Tec_Dummy <- ble1_Tec_T %>% select(Tec_name, julres, jultrav)
gen_tec_xml(out_dir = getwd(), param_df = ble1_Tec_Dummy, file = exampleTecFile)
# But what if i want them all?
When working with usm, soil, or stations, things seems to be clearer.
fixed on https://github.com/SticsRPacks/SticsRFiles/tree/master thanks!
To put usms according to a xml usm file inside a dataframe, i did use get_usms_list and then get_parama_xml.
Is there a more straightforward way to do this?