From ca30d1dbbfd764444a0c58d7270e6f9e82edd05e Mon Sep 17 00:00:00 2001 From: eibanez Date: Thu, 29 Jan 2015 09:06:38 -0700 Subject: [PATCH] More robust loops Do not use 1:length() --- R/plexos_open.R | 12 +++++------- R/process_solution.R | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/R/plexos_open.R b/R/plexos_open.R index 3cdee03..16bc758 100644 --- a/R/plexos_open.R +++ b/R/plexos_open.R @@ -90,17 +90,15 @@ plexos_open <- function(folders = ".", names = folders) { "Rerun process_folder() to avoid problems.", call. = FALSE) } else { - # Compare - comp <- integer(length(conf$rplexos)) - for (i in 1:length(conf$rplexos)) - comp[i] <- compareVersion(this.vers, conf$rplexos[i]) + # Compare to installed version + comp <- sapply(conf$rplexos, compareVersion, this.vers) - if (any(comp == -1)) { + if (any(comp > 0)) { warning("File(s) processed with a newer version of rplexos. ", "Update rplexos or rerun process_folder() to avoid problems.", call. = FALSE) - } else if (any(comp == 1)) { - warning("File(s) processed with an old version of rplexos. ", + } else if (any(comp < 0)) { + warning("File(s) processed with an older version of rplexos. ", "Rerun process_folder() to avoid problems.", call. = FALSE) } diff --git a/R/process_solution.R b/R/process_solution.R index 485aea8..2700660 100644 --- a/R/process_solution.R +++ b/R/process_solution.R @@ -590,7 +590,7 @@ add_extra_tables <- function(db) { dbGetQuery(db$con, sql) # Fix time stamps in t_period_X (summary data) - for (i in 1:length(column.times)) { + for (i in seq_along(column.times)) { sql <- sprintf("INSERT INTO temp_period_%s SELECT %s, %s, min(interval_id), min(correct_time) time FROM temp_phase_%s