Skip to content

Commit

Permalink
Revert "readIniAPI fix to return list compatible with API" (#217)
Browse files Browse the repository at this point in the history
* Revert "readIniAPI fix to return list compatible with API (#213)"

* readIni fix read file generaldata
  • Loading branch information
berthetclement authored Jul 19, 2023
1 parent a3070bc commit 46c8267
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
1 change: 0 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ BUGFIXES :
* `readIniAPI()` read well file `generaldata` for sections "playlist" and "variables selection"
* `readClusterDesc()` minor fix in API mode


DATA :

* A test study in tar.gz format is available in version `v8.6.0`
Expand Down
21 changes: 10 additions & 11 deletions R/readIniFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ readIniFile <- function(file, stringsAsFactors = FALSE) {
pairs <- X[seq(starts[i], ends[i])]
pairs <- pairs[pairs != ""]
pairs <- strsplit(pairs, "=")

key <- lapply(pairs, `[`, 1)
key <- unlist(key)
key <- trimws(key)

value <- lapply(pairs, `[`, 2)
value <- as.list(trimws(unlist(value)))
value <- lapply(value, function(x) {
Expand All @@ -83,7 +83,7 @@ readIniFile <- function(file, stringsAsFactors = FALSE) {
utils::type.convert(x, as.is = TRUE)
}
})

L[[i]] <- value
names(L[[i]]) <- key
}
Expand All @@ -105,17 +105,12 @@ readIniAPI <- function(study_id, path, host, token = NULL) {
formatted = TRUE
)
)

# reformat list contains unnamed list
.format_list(api_get_ini_file)
}


# reformat list from JSON format
.format_list <- function(list_x){
# test if list() contains list()
is_named(list_x[[2]]$`playlist +`)

# check list to find sub list
check_class_list <- lapply(list_x, function(x)
lapply(x, class) %in% "list")
Expand Down Expand Up @@ -149,7 +144,11 @@ readIniAPI <- function(study_id, path, host, token = NULL) {
}
})

# return list reformated
append(list_x[-index_true],
list_to_reformat)
# return original list
if(identical(index_true, integer(0)))
list_x
else
# return list reformated
append(list_x[-index_true],
list_to_reformat)
}
9 changes: 0 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,4 @@ badge_api_ok <- function() {
}
badge_api_no <- function() {
"\\ifelse{html}{\\figure{badge_api_no.svg}{options: alt='Antares API NO'}}{Antares API: \\strong{NO}}"
}

is_named <- function(x) {
nms <- names(x)
if (is.null(nms))
return(FALSE)
if (any(!nzchar(nms)))
return(FALSE)
TRUE
}

0 comments on commit 46c8267

Please sign in to comment.