diff --git a/R/AAAClassDefinitions.R b/R/AAAClassDefinitions.R index 8ea4b5a7..61bc52ff 100644 --- a/R/AAAClassDefinitions.R +++ b/R/AAAClassDefinitions.R @@ -78,7 +78,6 @@ SsimLibrary <- setClass("SsimLibrary", contains = "SsimObject", #' Scenario. 0 indicates this is not a result Scenario #' @slot folderId integer. The folder in which the Scenario exists. If the Scenario #' exists at the root of the project, then this value is NULL. -#' @slot breakpoints list of Breakpoint objects (optional) #' @name Scenario-class #' @rdname Scenario-class #' @export Scenario @@ -86,8 +85,7 @@ Scenario <- setClass("Scenario", contains = "SsimObject", representation(projectId = "numeric", scenarioId = "numeric", parentId = "numeric", - folderId = "numeric", - breakpoints = "list")) + folderId = "numeric")) #' SyncroSim Project class #' diff --git a/R/addPackage.R b/R/addPackage.R index 73ad22f9..d587c697 100644 --- a/R/addPackage.R +++ b/R/addPackage.R @@ -25,7 +25,8 @@ NULL #' @examples #' \donttest{ #' # Install "stsim" and "stsimecodep" SyncroSim packages -#' installPackage("stsim") +#' installPackage(packages = c("stsim", "stsim"), +#' versions = c("4.0.0", "4.0.1")) #' installPackage("stsimecodep") #' #' # Specify file path and name of new SsimLibrary diff --git a/R/autogentags.R b/R/autogentags.R deleted file mode 100644 index eb2b11ac..00000000 --- a/R/autogentags.R +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (c) 2024 Apex Resource Management Solution Ltd. (ApexRMS). All rights reserved. -# MIT License -#' @include AAAClassDefinitions.R -NULL - -#' Auto Generation Tags for a Scenario -#' -#' Retrieves or sets the Auto Generation Tags for a \code{\link{Scenario}}. -#' -#' @param ssimObject \code{\link{Scenario}} object -#' @param value character -#' -#' @return -#' Returns the Auto Generation Tags. -#' -#' @examples -#' \dontrun{ -#' # Get the Auto Generation Tags for a SyncroSim Scenario -#' autogentags(myScenario) -#' -#' # Set the Auto Generation Tags for a SyncroSim Scenario -#' autogentags(myScenario) <- "myTag" -#' } -#' -#' @export -setGeneric("autogentags", function(ssimObject) standardGeneric("autogentags")) - -#' @rdname autogentags -setMethod("autogentags", signature(ssimObject = "character"), function(ssimObject) { - return(SyncroSimNotFound(ssimObject)) -}) - -#' @rdname autogentags -setMethod("autogentags", signature(ssimObject = "Scenario"), function(ssimObject) { - scnInfo <- scenario(ssimObject, summary = TRUE) - return(scnInfo$autoGenTags) -}) - -#' @rdname autogentags -#' @export -setGeneric("autogentags<-", function(ssimObject, value) standardGeneric("autogentags<-")) - -#' @rdname autogentags -setReplaceMethod( - f = "autogentags", - signature = "character", - definition = function(ssimObject, value) { - return(ssimObject) - } -) - -#' @rdname autogentags -setReplaceMethod( - f = "autogentags", - signature = "Scenario", - definition = function(ssimObject, value) { - args <- list(setprop = NULL, lib = .filepath(ssimObject), autogentags = value, sid = .scenarioId(ssimObject)) - tt <- command(args, .session(ssimObject)) - if (!identical(tt, "saved")) { - stop(tt) - } - return(ssimObject) - } -) diff --git a/R/chart.R b/R/chart.R index 72a5b369..dbb8602c 100644 --- a/R/chart.R +++ b/R/chart.R @@ -36,7 +36,7 @@ setMethod( charts <- subset(charts, ChartId == chart) - # If no folders retrieved, then ID does not yet exist + # If no charts retrieved, then ID does not yet exist if (nrow(charts) == 0){ stop(paste0("The project does not contain the given chart ID ", chart, @@ -46,7 +46,7 @@ setMethod( if (create == TRUE) { stop(paste0("Cannot create a new chart from a chart ID. Please provide", - " a name for the new folder and the ID will be assigned", + " a name for the new chart and the ID will be assigned", " automatically.")) } @@ -123,14 +123,16 @@ setMethod( #' #' # Set the SyncroSim Session, SsimLibrary, Project, and Scenario #' mySession <- session() -#' myLibrary <- ssimLibrary(name = myLibraryName, session = mySession) +#' myLibrary <- ssimLibrary(name = myLibraryName, +#' session = mySession, +#' packages = "stsim") #' myProject <- project(myLibrary, project = "My Project") #' myScenario <- scenario(myProject, scenario = "My Scenario") #' #' # Create a new chart #' myChart <- chart(myProject, chart = "New Chart") #' } -#' @name folder +#' @name chart #' @export chart <- function(ssimObject = NULL, chart = NULL, create = FALSE, summary = FALSE){ @@ -140,7 +142,7 @@ chart <- function(ssimObject = NULL, chart = NULL, create = FALSE, summary = FAL # if ssimObject is a library throw an error if (is.element(class(ssimObject), c("SsimLibrary"))) { - stop("Cannot create a folder at the Library-level.") + stop("Cannot create a chart at the Library-level.") } # Return chart data if no chart argument is specified diff --git a/R/chartId.R b/R/chartId.R index cba3c5a8..2590edb9 100644 --- a/R/chartId.R +++ b/R/chartId.R @@ -15,12 +15,13 @@ NULL #' @examples #' \donttest{ #' # Set the file path and name of the new SsimLibrary -#' myLibraryName <- file.path(tempdir(),"testlib") +#' myLibraryName <- file.path(tempdir(), "testlib") #' #' # Set the SyncroSim Session, SsimLibrary, and Project #' mySession <- session() #' myLibrary <- ssimLibrary(name = myLibraryName, #' session = mySession, +#' packages = "stsim", #' overwrite = TRUE) #' myProject <- project(myLibrary, project = "Definitions") #' diff --git a/R/command.R b/R/command.R index 9574ee13..2d0501c4 100644 --- a/R/command.R +++ b/R/command.R @@ -42,8 +42,8 @@ NULL #' #' # Specify the command line arguments for creating a new stsim SsimLibrary #' args <- list(create = NULL, library = NULL, -#' name = myLibraryName, -#' package = "stsim") +#' name = myLibraryName, +#' package = "stsim") #' #' # Use a default session to create a new SsimLibrary in the current working directory #' output <- command(args, session = session(printCmd = TRUE)) diff --git a/R/datasheet.R b/R/datasheet.R index b8d9e744..33b4939c 100644 --- a/R/datasheet.R +++ b/R/datasheet.R @@ -113,9 +113,7 @@ NULL #' # Create a new SsimLibrary with the example template from helloworldSpatial #' myLibrary <- ssimLibrary(name = myLibraryName, #' session = mySession, -#' package = "helloworldSpatial", -#' template = "example-library", -#' forceUpdate = TRUE) +#' packages = "helloworldSpatial") #' #' # Set the Project and Scenario #' myProject <- project(myLibrary, project = "Definitions") @@ -129,28 +127,33 @@ NULL #' myDatasheetList <- datasheet(myScenario, summary = FALSE) #' #' # Get a specific Datasheet -#' myDatasheet <- datasheet(myScenario, name = "RunControl") +#' myDatasheet <- datasheet(myScenario, name = "helloworldSpatial_RunControl") #' #' # Include primary key when retrieving a Datasheet -#' myDatasheet <- datasheet(myScenario, name = "RunControl", includeKey = TRUE) +#' myDatasheet <- datasheet(myScenario, name = "helloworldSpatial_RunControl", +#' includeKey = TRUE) #' #' # Return all columns, including optional ones -#' myDatasheet <- datasheet(myScenario, name = "RunControl", summary = TRUE, -#' optional = TRUE) +#' myDatasheet <- datasheet(myScenario, name = "helloworldSpatial_RunControl", +#' summary = TRUE, optional = TRUE) #' #' # Return Datasheet as an element -#' myDatasheet <- datasheet(myScenario, name = "RunControl", forceElements = TRUE) +#' myDatasheet <- datasheet(myScenario, name = "helloworldSpatial_RunControl", +#' forceElements = TRUE) #' myDatasheet$helloworldSpatial_RunControl #' #' # Get a Datasheet without pre-specified values #' myDatasheetEmpty <- datasheet(myScenario, name = "RunControl", empty = TRUE) #' #' # If Datasheet is empty, do not return dependencies as factors -#' myDatasheetEmpty <- datasheet(myScenario, name = "RunControl", empty = TRUE, +#' myDatasheetEmpty <- datasheet(myScenario, +#' name = "helloworldSpatial_RunControl", +#' empty = TRUE, #' lookupsAsFactors = FALSE) #' #' # Optimize query -#' myDatasheet <- datasheet(myScenario, name = "RunControl", fastQuery = TRUE) +#' myDatasheet <- datasheet(myScenario, name = "helloworldSpatial_RunControl", +#' fastQuery = TRUE) #' #' # Get specific SsimLibrary core Datasheet #' myDatasheet <- datasheet(myLibrary, name = "core_Backup") @@ -161,7 +164,8 @@ NULL #' aggregate = c("MinimumTimestep"), #' where = list(MinimumTimestep = c(1)) #' ) -#' myAggregatedDatasheet <- datasheet(myScenario, name = "RunControl", +#' myAggregatedDatasheet <- datasheet(myScenario, +#' name = "helloworldSpatial_RunControl", #' sqlStatement = mySQL) #' } #' diff --git a/R/datasheetSpatRaster.R b/R/datasheetSpatRaster.R index 9404e631..60c9216f 100644 --- a/R/datasheetSpatRaster.R +++ b/R/datasheetSpatRaster.R @@ -66,10 +66,7 @@ NULL #' # Use the example template library from helloworldSpatial #' myLibrary <- ssimLibrary(name = myLibraryName, #' session = mySession, -#' package = "helloworldSpatial", -#' template = "example-library", -#' forceUpdate = TRUE, -#' overwrite=TRUE) +#' packages = "helloworldSpatial") #' #' # Set up Project and Scenario #' myProject <- project(myLibrary, project = "Definitions") @@ -80,18 +77,19 @@ NULL #' #' # Extract specific Datasheet rasters by iteration and timestep #' resultRaster <- datasheetSpatRaster(resultScenario, -#' datasheet = "IntermediateDatasheet", +#' datasheet = "helloworldSpatial_IntermediateDatasheet", #' column = "OutputRasterFile", #' iteration = 3, #' timestep = 2 #' ) #' #' # Extract specific Datasheet SpatRasters using pattern matching -#' resultDatasheet <- datasheet(resultScenario, name = "IntermediateDatasheet") +#' resultDatasheet <- datasheet(resultScenario, +#' name = "helloworldSpatial_IntermediateDatasheet") #' colnames(resultDatasheet) #' outputRasterPaths <- resultDatasheet$OutputRasterFile #' resultRaster <- datasheetSpatRaster(resultScenario, -#' datasheet = "IntermediateDatasheet", +#' datasheet = "helloworldSpatial_IntermediateDatasheet", #' column = "OutputRasterFile", #' subset = expression(grepl("ts20", #' outputRasterPaths, @@ -100,10 +98,9 @@ NULL #' #' # Return the raster Datasheets as a SpatRaster list #' resultRaster <- datasheetSpatRaster(resultScenario, -#' datasheet = "IntermediateDatasheet", +#' datasheet = "helloworldSpatial_IntermediateDatasheet", #' column = "OutputRasterFile", -#' forceElements = TRUE -#' ) +#' forceElements = TRUE) #' #' # Filter for only rasters that fit specific criteria #' # Load the ST-Sim spatial example library @@ -118,9 +115,7 @@ NULL #' # Create a new SsimLibrary with the example template from ST-Sim #' myLibrary <- ssimLibrary(name = myLibraryName, #' session = mySession, -#' package = "stsim", -#' template = "spatial-example", -#' forceUpdate = TRUE) +#' packages = "stsim") #' #' myScenario <- scenario(myLibrary, scenario = 16) #' diff --git a/R/deleteLibrary.R b/R/deleteLibrary.R index c6bbe259..150a3b6b 100644 --- a/R/deleteLibrary.R +++ b/R/deleteLibrary.R @@ -16,6 +16,26 @@ #' is FALSE. #' @param session Session #' @return "saved" or failure message. +#' +#' #' @examples +#' \donttest{ +#' # Specify file path and name of new SsimLibrary +#' myLibraryName <- file.path(tempdir(), "testlib") +#' +#' # Set up a SyncroSim Session and create SsimLibrary +#' mySession <- session() +#' myLibrary <- ssimLibrary(name = myLibraryName, session = mySession) +#' +#' # Delete library from SsimObject +#' deleteLibrary(myLibrary, force = TRUE, removeBackup = TRUE) +#' +#' # Create another library +#' myLibrary <- ssimLibrary(name = myLibraryName, session = mySession) +#' +#' # Delete library from path +#' deleteLibrary(myLibraryName) +#' } +#' #' @export setGeneric("deleteLibrary", diff --git a/R/folder.R b/R/folder.R index bb699c65..accda6f3 100644 --- a/R/folder.R +++ b/R/folder.R @@ -33,7 +33,7 @@ setMethod( } else if (is.numeric(folder)){ - folders <- subset(folders, Id == folder) + folders <- subset(folders, FolderId == folder) # If no folders retrieved, then ID does not yet exist if (nrow(folders) == 0){ @@ -54,8 +54,8 @@ setMethod( # If one folder retrieved, then open folder if ((nrow(folders) == 1) & (create == FALSE)) { - .Object@folderId <- folders$Id - .Object@parentId <- getParentFolderId(x, folders$Id) + .Object@folderId <- folders$FolderId + .Object@parentId <- getParentFolderId(x, folders$FolderId) .Object@session <- .session(x) .Object@filepath <- .filepath(x) .Object@projectId <- x@projectId @@ -78,10 +78,10 @@ setMethod( ". Please provide a valid parent folder name.")) } - ParentId <- parentFolderData$Id + ParentId <- parentFolderData$FolderId } else if (is.numeric(parentFolder)) { - parentFolderData <- subset(allFolders, Id == parentFolder) + parentFolderData <- subset(allFolders, FolderId == parentFolder) if (nrow(parentFolderData) == 0) { stop(paste0("The library does not contain a folder with the ID ", @@ -89,7 +89,7 @@ setMethod( ". Please provide a valid parent folder ID")) } - ParentId <- parentFolderData$Id + ParentId <- parentFolderData$FolderId } else { stop("The parentFolder argument must be a character, integer, or SyncroSim folder object.") @@ -220,15 +220,15 @@ folder <- function(ssimObject = NULL, folder = NULL, parentFolder = NULL, } } - folders <- folders[which(folders$Id %in% ids), ] + folders <- folders[which(folders$FolderId %in% ids), ] } # Subset dataframe by specified folder if summary == TRUE if (is(ssimObject, "Folder") & (summary == TRUE)){ - folders <- subset(folders, Id == .folderId(ssimObject)) + folders <- subset(folders, FolderId == .folderId(ssimObject)) } else if (!is.null(folder) & (summary == TRUE)){ if (is.numeric(folder)) { - folders <- subset(folders, Id == folder) + folders <- subset(folders, FolderId == folder) } else { folders <- subset(folders, Name == folder) } diff --git a/R/folderId.R b/R/folderId.R index 1b9f0f44..d5569d55 100644 --- a/R/folderId.R +++ b/R/folderId.R @@ -60,7 +60,7 @@ setMethod("folderId", signature(ssimObject = "Scenario"), function(ssimObject) { item="Scenario") folderInfo <- getFolderData(ssimObject) - if (!parentFolderId %in% folderInfo$Id){ + if (!parentFolderId %in% folderInfo$FolderId){ parentFolderId <- NA } diff --git a/R/name.R b/R/name.R index 76a5e26c..440d7d72 100644 --- a/R/name.R +++ b/R/name.R @@ -22,7 +22,9 @@ NULL #' #' # Set up a SyncroSim Session, SsimLibrary, Project, and Scenario #' mySession <- session() -#' myLibrary <- ssimLibrary(name = myLibraryName, session = mySession) +#' myLibrary <- ssimLibrary(name = myLibraryName, +#' session = mySession, +#' packages = "stsim") #' myProject <- project(myLibrary, project = "Definitions") #' myScenario <- scenario(myProject, scenario = "My Scenario") #' myFolder <- folder(myProject, folder = "New Folder") diff --git a/R/packages.R b/R/packages.R index 25ec4e48..e46e4f20 100644 --- a/R/packages.R +++ b/R/packages.R @@ -31,9 +31,6 @@ NULL #' # List all installed packages #' packages(mySession) #' -#' # List all the installed base packages -#' packages(installed = "BASE") -#' #' # List all available packages on the server (including currently installed) #' packages(installed = FALSE) #' diff --git a/R/parentId.R b/R/parentId.R index 50b24d45..90fba291 100644 --- a/R/parentId.R +++ b/R/parentId.R @@ -17,19 +17,13 @@ NULL #' #' @examples #' \dontrun{ -#' # Install helloworldSpatial SyncroSim package -#' installPackage("helloworldSpatial") -#' -#' # Set the file path and name of the new SsimLibrary -#' myLibraryName <- file.path(tempdir(),"testlib_parentId") +#' # Set the file path and name of an existing SsimLibrary +#' myLibraryName <- "MyLibrary.ssim" #' #' # Set the SyncroSim Session, SsimLibrary, Project, and Scenario #' mySession <- session() #' myLibrary <- ssimLibrary(name = myLibraryName, -#' session = mySession, -#' package = "helloworldSpatial", -#' template = "example-library", -#' forceUpdate = TRUE) +#' session = mySession) #' myProject <- project(myLibrary, project = "Definitions") #' myScenario <- scenario(myProject, scenario = "My Scenario") #' diff --git a/R/runLog.R b/R/runLog.R index 7ec593bb..6bca9c44 100644 --- a/R/runLog.R +++ b/R/runLog.R @@ -14,19 +14,13 @@ NULL #' #' @examples #' \dontrun{ -#' # Install helloworldSpatial package -#' installPackage("helloworldSpatial") -#' -#' # Set the file path and name of the new SsimLibrary -#' myLibraryName <- file.path(tempdir(),"testlib") +#' # Set the file path and name of an existing SsimLibrary +#' myLibraryName <- file.path("MyLibrary.ssim") #' #' # Set the SyncroSim Session, SsimLibrary, Project, and Scenario #' mySession <- session() #' myLibrary <- ssimLibrary(name = myLibraryName, -#' session = mySession, -#' package = "helloworldSpatial", -#' template = "example-library", -#' forceUpdate = TRUE) +#' session = mySession) #' myProject <- project(myLibrary, project = "Definitions") #' myScenario <- scenario(myProject, scenario = "My Scenario") #' diff --git a/R/saveDatasheet.R b/R/saveDatasheet.R index b9e9852c..341e9dfe 100644 --- a/R/saveDatasheet.R +++ b/R/saveDatasheet.R @@ -65,19 +65,14 @@ NULL #' #' @examples #' \dontrun{ -#' # Install helloworldSpatial package -#' installPackage("helloworldSpatial") -#' -#' # Set the file path and name of the new SsimLibrary -#' myLibraryName <- file.path(tempdir(),"testlib_saveDatasheet") +#' # Specify file path and name of new SsimLibrary +#' myLibraryName <- file.path(tempdir(), "testlib") #' #' # Set the SyncroSim Session, SsimLibrary, Project, and Scenario #' mySession <- session() #' myLibrary <- ssimLibrary(name = myLibraryName, -#' session = mySession, -#' package = "helloworldSpatial", -#' template = "example-library", -#' forceUpdate = TRUE) +#' session = mySession, +#' packages = "helloworldSpatial") #' myProject <- project(myLibrary, project = "Definitions") #' myScenario <- scenario(myProject, scenario = "My Scenario") #' @@ -85,35 +80,43 @@ NULL #' myDatasheets <- datasheet(myScenario) #' #' # Get a specific Datasheet -#' myDatasheet <- datasheet(myScenario, name = "RunControl") +#' myDatasheet <- datasheet(myScenario, name = "helloworldSpatial_RunControl") #' #' # Modify Datasheet #' myDatasheet$MaximumTimestep <- 10 #' #' # Save Datasheet -#' saveDatasheet(ssimObject = myScenario, data = myDatasheet, name = "RunControl") +#' saveDatasheet(ssimObject = myScenario, +#' data = myDatasheet, +#' name = "helloworldSpatial_RunControl") #' #' # Import data after saving -#' saveDatasheet(ssimObject = myScenario, data = myDatasheet, name = "RunControl", +#' saveDatasheet(ssimObject = myScenario, +#' data = myDatasheet, +#' name = "helloworldSpatial_RunControl", #' import = TRUE) #' #' # Save the new Datasheet to a specified output path -#' saveDatasheet(ssimObject = myScenario, data = myDatasheet, name = "RunControl", +#' saveDatasheet(ssimObject = myScenario, +#' data = myDatasheet, +#' name = "helloworldSpatial_RunControl", #' path = tempdir()) #' #' # Save a raster stack using fileData #' # Create a raster stack - add as many raster files as you want here -#' map1 <- datasheetSpatRaster(myScenario, datasheet = "InputDatasheet", -#' column = "InterceptRasterFile") +#' map1 <- datasheetSpatRaster(myScenario, +#' datasheet = "helloworldSpatial_InputDatasheet", +#' column = "InterceptRasterFile") #' inRasters <- terra::rast(map1) #' #' # Change the name of the rasters in the input Datasheets to match the stack -#' inSheet <- datasheet(myScenario, name="InputDatasheet") +#' inSheet <- datasheet(myScenario, name = "helloworldSpatial_InputDatasheet") #' inSheet[1,"InterceptRasterFile"] <- names(inRasters)[1] #' #' # Save the raster stack to the input Datasheet -#' saveDatasheet(myScenario, data=inSheet, name="InputDatasheet", -#' fileData=inRasters) +#' saveDatasheet(myScenario, data = inSheet, +#' name = "helloworldSpatial_InputDatasheet", +#' fileData = inRasters) #' } #' #' @export diff --git a/R/sqlStatement.R b/R/sqlStatement.R index da105379..83359b13 100644 --- a/R/sqlStatement.R +++ b/R/sqlStatement.R @@ -39,21 +39,17 @@ NULL #' where = list(Timestep = c(0, 1, 2), Iteration = c(3, 4)) #' ) #' mySQL -#' +#' } +#' \dontrun{ #' # The SQL statement can then be used in the datasheet function -#' # Install helloworldSpatial package -#' installPackage("helloworldSpatial") #' -#' # Set the file path and name of the new SsimLibrary -#' myLibraryName <- file.path(tempdir(),"testlib_sqlStatement") +#' # Set the file path and name of an existing SsimLibrary +#' myLibraryName <- file.path("MyLibrary.ssim") #' #' # Set the SyncroSim Session, SsimLibrary, Project, and Scenario #' mySession <- session() #' myLibrary <- ssimLibrary(name = myLibraryName, -#' session = mySession, -#' package = "helloworldSpatial", -#' template = "example-library", -#' forceUpdate = TRUE) +#' session = mySession) #' myProject <- project(myLibrary, project = "Definitions") #' myScenario <- scenario(myProject, scenario = "My Scenario") #' @@ -61,7 +57,8 @@ NULL #' resultScenario <- run(myScenario) #' #' # Use the SQL statement when loading the Datasheet -#' myAggregatedDataFrame <- datasheet(resultScenario, name = "OutputDatasheet", +#' myAggregatedDataFrame <- datasheet(resultScenario, +#' name = "helloworldSpatial_OutputDatasheet", #' sqlStatement = mySQL) #' #' # View aggregated DataFrame diff --git a/R/uninstallPackage.R b/R/uninstallPackage.R index e6d0aa54..8786b034 100644 --- a/R/uninstallPackage.R +++ b/R/uninstallPackage.R @@ -19,12 +19,17 @@ NULL #' #' @examples #' \donttest{ -#' # Set SyncroSim Session +#' # Set SyncroSim session #' mySession <- session() #' -#' # Uninstalls package from SyncroSim Session +#' # Install packages to SyncroSim session +#' installPackages(packages = c("stsim", "stsim"), +#' versions = c("4.0.0", "4.0.1")) +#' +#' # Uninstalls specific version of package from SyncroSim session #' uninstallPackage(packages = "stsim", versions = "4.0.0", session = mySession) #' +#' # Uninstalls all instances ofa package from SyncroSim session #' uninstallPackage(packages = "stsim", session = mySession) #' } #'