ConfigEditEntry <- function(configuration, dataset_type, store_format, dataset_name = NULL, var_name = NULL, level = NULL, position = NULL, main_path = NULL, file_path = NULL, nc_var_name = NULL, grid = NULL, suffix = NULL, varmin = NULL, varmax = NULL) {
  table_name <- paste0(gsub("-", "_", store_format), "_", dataset_type)
  if (!is.null(dataset_name) && !is.null(var_name)) {
    if (dataset_name == ".*") {
      if (var_name == ".*") {
        level <- 1
      } else {
        level <- 3
      }
    } else {
      if (var_name == ".*") {
        level <- 2
      } else {
        level <- 4
      }
    }

    position <- which(unlist(lapply(configuration[[table_name]][[level]], "[", 1)) == dataset_name &
                         unlist(lapply(configuration[[table_name]][[level]], "[", 2)) == var_name)[1]
    if (is.na(position)) {
      stop("No entry found that matches 'dataset_name' and 'var_name'.")
    }
  } else if (is.null(level) || is.null(position)) {
    stop("At least one of the couples ('dataset_name', 'var_name') or ('level', 'position') must be specified.")
  }
  
  level_entries <- length(configuration[[table_name]][[level]])
  if (position < 1 || position > level_entries + 1) {
    stop("'position' must be in the range [1, # of existing table entries in corresponding level]")
  }

  if (dataset_type == 'experiments') {
    edited_values <- c(1:9)[c(!is.null(dataset_name), !is.null(var_name), !is.null(main_path), !is.null(file_path), !is.null(nc_var_name), !is.null(grid), !is.null(suffix), !is.null(varmin), !is.null(varmax))]
    configuration[[table_name]][[level]][[position]][edited_values] <- c(dataset_name, var_name, main_path, file_path, nc_var_name, grid, suffix, varmin, varmax)
  } else if (dataset_type == 'observations') {
    edited_values <- c(1:8)[c(!is.null(dataset_name), !is.null(var_name), !is.null(main_path), !is.null(file_path), !is.null(nc_var_name), !is.null(suffix), !is.null(varmin), !is.null(varmax))]
    configuration[[table_name]][[level]][[position]][edited_values] <- c(dataset_name, var_name, main_path, file_path, nc_var_name, suffix, varmin, varmax)
  } else {
    stop("'dataset_type' must be one of 'experiments' or 'observations'")
  }

  configuration
}
