Skip to content

Commit

Permalink
allow for retuning both yml ext. Always return as fs path vector.
Browse files Browse the repository at this point in the history
  • Loading branch information
annakrystalli committed Sep 15, 2023
1 parent 99864c0 commit ce530a9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,30 @@ get_file_round_id_col <- function(file_path, hub_path) {

# Get metadata dile name from submission file path
get_metadata_file_name <- function(hub_path, file_path,
ext = c("yml", "yaml", "auto")) {
ext = c("yml", "yaml", "auto", "both")) {
ext <- rlang::arg_match(ext)
model_id <- parse_file_name(file_path)$model_id

if (ext == "both") {
return(fs::path(c(
fs::path(model_id, ext = "yml"),
fs::path(model_id, ext = "yaml")
)))
}

if (ext == "auto") {
meta_file_names <- c(
meta_file_names <- fs::path(c(
fs::path(model_id, ext = "yml"),
fs::path(model_id, ext = "yaml")
)
))
meta_file_paths <- abs_file_path(
meta_file_names,
hub_path,
subdir = "model-metadata"
)
exist <- fs::file_exists(meta_file_paths)
if (any(exist)) {
return(fs::path(meta_file_names[exist][1]))
return(meta_file_names[exist][1])
} else {
cli::cli_abort(
"Model metadata file name could not be automatically detected for file {.path {file_path}}"
Expand Down

0 comments on commit ce530a9

Please sign in to comment.