From ed607cc7168aeaa8910e22e4365c9fff0162b799 Mon Sep 17 00:00:00 2001 From: katieb1 Date: Mon, 15 Apr 2024 16:27:49 -0700 Subject: [PATCH] Port bug fixes from 1.5 to 2 --- R/saveDatasheet.R | 35 +++++++++++---------- R/scenario.R | 26 +++++++-------- R/session.R | 6 ++-- R/ssimEnvironment.R | 8 +++++ R/ssimLibrary.R | 22 +++++-------- vignettes/a01_rsyncrosim_vignette_basic.Rmd | 2 +- 6 files changed, 52 insertions(+), 47 deletions(-) diff --git a/R/saveDatasheet.R b/R/saveDatasheet.R index 38ac1842..235622fb 100644 --- a/R/saveDatasheet.R +++ b/R/saveDatasheet.R @@ -224,38 +224,41 @@ setMethod("saveDatasheet", signature(ssimObject = "SsimObject"), function(ssimOb } # Subset data by available columns - tt <- command(c("list", "columns", "csv", "allprops", paste0("lib=", .filepath(x)), paste0("sheet=", name)), .session(x)) + tt <- command(c("list", "columns", "csv", "allprops", + paste0("lib=", .filepath(x)), + paste0("sheet=", name)), .session(x)) sheetInfo <- .dataframeFromSSim(tt) + + # Remove the library/project/scenario ID from the datasheet if (scope == "library"){ - colsToKeep <- sheetInfo$name[2:length(sheetInfo$name)] - } else { - colsToKeep <- sheetInfo$name[3:length(sheetInfo$name)] + colsToKeep <- sheetInfo$name[!sheetInfo$name %in% c("LibraryID")] + } else if (scope == "project"){ + colsToKeep <- sheetInfo$name[!sheetInfo$name %in% c("ProjectID")] + } else if (scope == "scenario"){ + colsToKeep <- sheetInfo$name[!sheetInfo$name %in% c("ScenarioID")] } + + # Remove the datasheet ID from the datasheet if it exists + dsInfo <- sheetNames[sheetNames$name == cName,] + dsName <- gsub(paste0(dsInfo$package, "_"), '', dsInfo$name) + dsNameID <- paste0(dsName, "ID") + colsToKeep <- colsToKeep[!colsToKeep %in% c(dsNameID)] + + # Subset data by the valid columns colsToKeep <- colnames(cDat)[colnames(cDat) %in% colsToKeep] cDat <- cDat[colsToKeep] # if no fileData found and datasheet contains files, find the files if (is.null(fileData)) { - # get info on sheet type - # tt <- command(c("list", "columns", "csv", "allprops", paste0("lib=", .filepath(x)), paste0("sheet=", name)), .session(x)) - # sheetInfo <- .dataframeFromSSim(tt) + if (sum(grepl("isExternalFile^True", sheetInfo$properties, fixed = TRUE)) > 0) { sheetInfo$isFile <- grepl("isRaster^True", sheetInfo$properties, fixed = TRUE) } else { sheetInfo$isFile <- grepl("isExternalFile^Yes", sheetInfo$properties, fixed = TRUE) # NOTE: this should be isExternalFile - but the flag is set to true even for non-files } - # We only want to keep the valid columns in cDat (not scenario ID, etc.) - # if (scope == "library"){ - # colsToKeep <- sheetInfo$name[2:length(sheetInfo$name)] - # } else { - # colsToKeep <- sheetInfo$name[3:length(sheetInfo$name)] - # } - # colsToKeep <- colnames(cDat)[colnames(cDat) %in% colsToKeep] - # cDat <- cDat[colsToKeep] sheetInfo <- subset(sheetInfo, isFile) - sheetInfo <- subset(sheetInfo, is.element(name, names(cDat))) } diff --git a/R/scenario.R b/R/scenario.R index 63eacee3..de367380 100644 --- a/R/scenario.R +++ b/R/scenario.R @@ -180,20 +180,20 @@ setMethod( #' #' For each element of Scenario: #' \itemize{ -#' \item {If element/Project/SsimObject uniquely identifies an existing -#' Scenario: }{Returns the existing Scenario}. -#' \item {If element/Project/SsimObject uniquely identifies more than one existing -#' Scenario: }{Error}. -#' \item {If element/Project/SsimObject do not identify an existing Scenario or -#' Project: }{Error}. -#' \item {If element/Project/SsimObject do not identify an existing Scenario and -#' element is numeric: }{Error - a name is required for new Scenarios. -#' SyncroSim will automatically assign an id when a Scenario is created.} -#' \item {If element/Project/SsimObject do not identify an existing Scenario and -#' do identify a Project, and element is a character string: }{Creates a +#' \item If element/Project/SsimObject uniquely identifies an existing +#' Scenario: Returns the existing Scenario. +#' \item If element/Project/SsimObject uniquely identifies more than one existing +#' Scenario: Error. +#' \item If element/Project/SsimObject do not identify an existing Scenario or +#' Project: Error. +#' \item If element/Project/SsimObject do not identify an existing Scenario and +#' element is numeric: Error - a name is required for new Scenarios. +#' SyncroSim will automatically assign an id when a Scenario is created. +#' \item If element/Project/SsimObject do not identify an existing Scenario and +#' do identify a Project, and element is a character string: Creates a #' new Scenario named element in the Project. SyncroSim automatically -#' assigns an id. If sourceScenario is not \code{NULL} the new Scenario will be -#' a copy of sourceScenario.} +#' assigns an id. If sourceScenario is not \codeNULL the new Scenario will be +#' a copy of sourceScenario. #' } #' #' @examples diff --git a/R/session.R b/R/session.R index 65304f4a..eafca64d 100644 --- a/R/session.R +++ b/R/session.R @@ -13,7 +13,7 @@ setMethod(f = "initialize", signature = "Session", definition = function(.Object .Object@printCmd <- printCmd .Object@condaFilepath <- NULL - ssimRequiredVersion <- "2.4.44" + ssimRequiredVersion <- "3.0.0" ssimCurrentVersion <- command(list(version = NULL), .Object) rsyncrosimVersion <- packageVersion("rsyncrosim") @@ -27,7 +27,7 @@ setMethod(f = "initialize", signature = "Session", definition = function(.Object loadVersion <- FALSE if (ssimCurrentVersionBits[1] >= ssimRequiredVersionBits[1]){ - if (ssimCurrentVersionBits[1] > ssimRequiredVersion[1]) { + if (ssimCurrentVersionBits[1] > ssimRequiredVersionBits[1]) { loadVersion <- TRUE } else { if (ssimCurrentVersionBits[2] >= ssimRequiredVersionBits[2]){ @@ -35,7 +35,7 @@ setMethod(f = "initialize", signature = "Session", definition = function(.Object loadVersion <- TRUE } else { if (ssimCurrentVersionBits[3] >= ssimRequiredVersionBits[3]){ - if (ssimCurrentVersionBits[3] > ssimRequiredVersionBits[3]){ + if (ssimCurrentVersionBits[3] >= ssimRequiredVersionBits[3]){ loadVersion <- TRUE } } diff --git a/R/ssimEnvironment.R b/R/ssimEnvironment.R index 475a4234..47d0d5b3 100644 --- a/R/ssimEnvironment.R +++ b/R/ssimEnvironment.R @@ -270,6 +270,14 @@ updateRunLog <- function(..., sep = "", type = "status") { # Annotate messages annotatedMessage <- paste0("ssim-task-log=", splitMessage, "\r\n") + if(!type %in% c("status", "info", "warning")) + stop("Please select a valid run log message type.") + + if(type == "info") + annotatedMessage[1] <- sub("ssim-task-log", "ssim-task-info", annotatedMessage[1]) + if(type == "warning") + annotatedMessage[1] <- sub("ssim-task-log", "ssim-task-warning", annotatedMessage[1]) + # Send to SyncroSim for(m in annotatedMessage) { cat(m) diff --git a/R/ssimLibrary.R b/R/ssimLibrary.R index 9f9e7742..a7654655 100644 --- a/R/ssimLibrary.R +++ b/R/ssimLibrary.R @@ -105,12 +105,6 @@ setMethod( stop("Problem creating library: ", cStatus[1]) } - # Print out available scenarios for the template - args <- list(list = NULL, scenarios = NULL, lib = path, csv = NULL) - tt <- command(args, session) - tempScenarios <- read.csv(text = tt) - message(paste(c("Scenarios available in this template:", - tempScenarios$Name), collapse = "\n")) } else { stop(paste(template, "does not exist among packages selected:", packages)) } @@ -244,17 +238,17 @@ setMethod(".ssimLibrary", signature(name = "SsimObject"), #' @details #' Example arguments: #' \itemize{ -#' \item {If name is SyncroSim Project or Scenario: }{Returns the -#' \code{\link{SsimLibrary}} associated with the Project or Scenario.} -#' \item {If name is \code{NULL}: }{Create/open a SsimLibrary in the current working -#' directory with the filename SsimLibrary.ssim.} -#' \item {If name is a string: }{If string is not a valid path treat as filename +#' \item If name is SyncroSim Project or Scenario: Returns the +#' \code\linkSsimLibrary associated with the Project or Scenario. +#' \item If name is \codeNULL: Create/open a SsimLibrary in the current working +#' directory with the filename SsimLibrary.ssim. +#' \item If name is a string: If string is not a valid path treat as filename #' in working directory. If no file suffix provided in string then add #' .ssim. Attempts to open a SsimLibrary of that name. If SsimLibrary does not -#' exist creates a SsimLibrary of type package in the current working directory.} -#' \item {If given a name and a package: }{Create/open a SsimLibrary called [name].ssim. +#' exist creates a SsimLibrary of type package in the current working directory. +#' \item If given a name and a package: Create/open a SsimLibrary called [name].ssim. #' Returns an error if the SsimLibrary already exists but is a different type -#' of package.} +#' of package. #' } #' #' @examples diff --git a/vignettes/a01_rsyncrosim_vignette_basic.Rmd b/vignettes/a01_rsyncrosim_vignette_basic.Rmd index 012ca465..1c90056b 100644 --- a/vignettes/a01_rsyncrosim_vignette_basic.Rmd +++ b/vignettes/a01_rsyncrosim_vignette_basic.Rmd @@ -259,7 +259,7 @@ Each SyncroSim Library contains multiple SyncroSim