Mercurial > repos > siwaa > redelac_stics_t
comparison redelacSticsTool.R @ 22:15317ef4816b draft
"planemo upload for repository https://forgemia.inra.fr/redelac commit 3867fb88de7181d8703dec0b69d1f03a9a36b34b"
| author | siwaa |
|---|---|
| date | Tue, 21 Jul 2026 14:23:47 +0000 |
| parents | 5dcba002e019 |
| children | 3b44cb0a1e76 |
comparison
equal
deleted
inserted
replaced
| 21:5dcba002e019 | 22:15317ef4816b |
|---|---|
| 64 ) | 64 ) |
| 65 | 65 |
| 66 # Tec files loading and generating xml | 66 # Tec files loading and generating xml |
| 67 | 67 |
| 68 tec_param <- read_params_table(file.path(workspace, TecFile)) | 68 tec_param <- read_params_table(file.path(workspace, TecFile)) |
| 69 | |
| 70 # sanitizing (trying to) | |
| 71 | |
| 72 paramDesc = SticsRFiles:::get_param_desc() | |
| 73 | |
| 74 paramTecDesc <- paramDesc[paramDesc$kind=="PARTEC",] | |
| 75 | |
| 76 expectedTypes <- setNames(as.list(paramTecDesc$type), paramTecDesc$name) | |
| 77 | |
| 78 expectedTypes <- lapply(expectedTypes, function(x) { | |
| 79 if (identical(x, "real")) "numeric" else x | |
| 80 }) | |
| 81 | |
| 82 check <- sapply(names(tec_param), function(col) { | |
| 83 colref <- col | |
| 84 col <- sub("_[0-9]+$", "", col) | |
| 85 if (!col %in% names(expectedTypes)) { | |
| 86 NA | |
| 87 } else { | |
| 88 class(tec_param[[colref]])[1] == expectedTypes[[col]] | |
| 89 } | |
| 90 }) | |
| 91 | |
| 92 finalCheck <- check[!is.na(check)] | |
| 93 | |
| 94 toFix <- finalCheck[sapply(finalCheck, function(x) x == FALSE)] | |
| 95 | |
| 96 converters <- list( | |
| 97 integer = as.integer, | |
| 98 numeric = as.numeric, | |
| 99 character = as.character, | |
| 100 logical = as.logical, | |
| 101 factor = as.factor, | |
| 102 Date = as.Date | |
| 103 ) | |
| 104 | |
| 105 for (col in names(toFix)) { | |
| 106 if (col %in% names(tec_param)) { | |
| 107 type <- expectedTypes[[sub("_[0-9]+$", "", col)]] | |
| 108 if (type %in% names(converters)) { | |
| 109 tec_param[[col]] <- converters[[type]](tec_param[[col]]) | |
| 110 } else { | |
| 111 warning(sprintf("Unknown type '%s' for column '%s'", type, col)) | |
| 112 } | |
| 113 } | |
| 114 } | |
| 115 | |
| 69 columnToRemove <- | 116 columnToRemove <- |
| 70 names(tec_param[grep("juleclair|nbinfloecl", names(tec_param))]) | 117 names(tec_param[grep("juleclair|nbinfloecl", names(tec_param))]) |
| 71 columnToKeep <- | 118 columnToKeep <- |
| 72 names(tec_param)[names(tec_param) %in% columnToRemove == FALSE] | 119 names(tec_param)[names(tec_param) %in% columnToRemove == FALSE] |
| 73 | 120 |
