Skip to content

Commit

Permalink
Remove unutilized variables from convert_input
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinav Pandey <[email protected]>
  • Loading branch information
Sweetdevil144 committed Jul 25, 2024
1 parent d5e8d24 commit f22b962
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
12 changes: 11 additions & 1 deletion base/db/R/add.database.entries.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 8 additions & 10 deletions base/db/R/check.missing.files.R
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -18,32 +18,30 @@ 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)]),
"\n Table of results printed above.",
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))
}
6 changes: 2 additions & 4 deletions base/db/R/convert_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f22b962

Please sign in to comment.