diff --git a/base/db/R/add.database.entries.R b/base/db/R/add.database.entries.R index 3c253c07e7..d3eb994a64 100644 --- a/base/db/R/add.database.entries.R +++ b/base/db/R/add.database.entries.R @@ -33,6 +33,7 @@ add.database.entries <- function( # Setup newinput. This list will contain two variables: a vector of input IDs and a vector of DB IDs for each entry in result. # This list will be returned. newinput <- list(input.id = NULL, dbfile.id = NULL) # Blank vectors are null. + for (i in 1:length(result)) { # Master for loop id_not_added <- TRUE @@ -72,7 +73,16 @@ add.database.entries <- function( } if (insert.new.file && id_not_added) { - dbfile.id <- dbfile.insert(in.path = dirname(result[[i]]$file[1]), in.prefix = result[[i]]$dbfile.name[1], "Input", existing.input[[i]]$id, con, reuse = TRUE, hostname = machine$hostname) + dbfile.id <- dbfile.insert( + in.path = dirname(result[[i]]$file[1]), + in.prefix = result[[i]]$dbfile.name[1], + "Input", + existing.input[[i]]$id, + con, + reuse = TRUE, + hostname = machine$hostname + ) + newinput$input.id <- c(newinput$input.id, existing.input[[i]]$id) newinput$dbfile.id <- c(newinput$dbfile.id, dbfile.id) } else if (id_not_added) { diff --git a/base/db/R/check.missing.files.R b/base/db/R/check.missing.files.R index bde3d7ebe9..617878496d 100644 --- a/base/db/R/check.missing.files.R +++ b/base/db/R/check.missing.files.R @@ -1,11 +1,11 @@ #' Function to check if result has empty or missing files -#' +#' #' @param result A list of dataframes with file paths #' @param outname Name of the output file #' @param existing.input Existing input records #' @param existing.dbfile Existing dbfile records #' @return A list of dataframes with file paths, a list of strings with the output file name, a list of existing input records, and a list of existing dbfile records -#' +#' #' @author Betsy Cowdery, Michael Dietze, Ankur Desai, Tony Gardella, Luke Dramko check_missing_files <- function(result, outname, existing.input = NULL, existing.dbfile = NULL) { @@ -18,14 +18,14 @@ check_missing_files <- function(result, outname, existing.input = NULL, existing empty = file_size == 0 ) ) - + if (any(result_sizes$missing) || any(result_sizes$empty)) { log_format_df <- function(df) { formatted_df <- rbind(colnames(df), format(df)) formatted_text <- purrr::reduce(formatted_df, paste, sep = " ") paste(formatted_text, collapse = "\n") } - + PEcAn.logger::logger.severe( "Requested Processing produced empty files or Nonexistent files:\n", log_format_df(result_sizes[, c(1, 8, 9, 10)]), @@ -33,17 +33,15 @@ check_missing_files <- function(result, outname, existing.input = NULL, existing wrap = FALSE ) } - - # Insert into Database - outlist <- unlist(strsplit(outname, "_")) - + + # Wrap in a list for consistant processing later if (exists("existing.input") && is.data.frame(existing.input)) { existing.input <- list(existing.input) } - + if (exists("existing.dbfile") && is.data.frame(existing.dbfile)) { existing.dbfile <- list(existing.dbfile) } - return(list(result_sizes, outlist, existing.input, existing.dbfile)) + return(list(existing.input, existing.dbfile)) } diff --git a/base/db/R/convert_input.R b/base/db/R/convert_input.R index d5af069d0e..265559798b 100644 --- a/base/db/R/convert_input.R +++ b/base/db/R/convert_input.R @@ -737,10 +737,8 @@ convert_input <- checked.missing.files <- check_missing_files(result, outname, existing.input, existing.dbfile) # Unwrap parameters after performing checks for missing files - result_sizes <- checked.missing.files$result_sizes; - outlist <- checked.missing.files$outlist; - existing.input <- checked.missing.files$existing.input; - existing.dbfile <- checked.missing.files$existing.dbfile; + existing.input <- checked.missing.files$existing.input + existing.dbfile <- checked.missing.files$existing.dbfile #---------------------------------------------------------------# # New arrangement of database adding code to deal with ensembles.