Skip to content

Commit

Permalink
Port bug fixes from 1.5 to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
katieb1 committed Apr 15, 2024
1 parent aa5ce6e commit ed607cc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 47 deletions.
35 changes: 19 additions & 16 deletions R/saveDatasheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

Expand Down
26 changes: 13 additions & 13 deletions R/scenario.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions R/session.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -27,15 +27,15 @@ 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]){
if (ssimCurrentVersionBits[2] > ssimRequiredVersionBits[2]) {
loadVersion <- TRUE
} else {
if (ssimCurrentVersionBits[3] >= ssimRequiredVersionBits[3]){
if (ssimCurrentVersionBits[3] > ssimRequiredVersionBits[3]){
if (ssimCurrentVersionBits[3] >= ssimRequiredVersionBits[3]){
loadVersion <- TRUE
}
}
Expand Down
8 changes: 8 additions & 0 deletions R/ssimEnvironment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 8 additions & 14 deletions R/ssimLibrary.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vignettes/a01_rsyncrosim_vignette_basic.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Each SyncroSim Library contains multiple SyncroSim <a href="https://docs.syncros
datasheet(myScenario)
```

If we want to see more information about each Datasheet, such as the scope of the Datasheet or if it only accepts a single row of data, we can set the `optional` argument to `FALSE`.
If we want to see more information about each Datasheet, such as the scope of the Datasheet or if it only accepts a single row of data, we can set the `optional` argument to `TRUE`.

```{r}
datasheet(myScenario, optional = TRUE)
Expand Down

0 comments on commit ed607cc

Please sign in to comment.