Skip to content

Commit

Permalink
Fix bugs and example docs unearthed by building reference
Browse files Browse the repository at this point in the history
  • Loading branch information
katieb1 committed Oct 13, 2024
1 parent 4ed4579 commit 9a513e2
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 162 deletions.
4 changes: 1 addition & 3 deletions R/AAAClassDefinitions.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ 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
Scenario <- setClass("Scenario", contains = "SsimObject",
representation(projectId = "numeric",
scenarioId = "numeric",
parentId = "numeric",
folderId = "numeric",
breakpoints = "list"))
folderId = "numeric"))

#' SyncroSim Project class
#'
Expand Down
3 changes: 2 additions & 1 deletion R/addPackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 0 additions & 64 deletions R/autogentags.R

This file was deleted.

12 changes: 7 additions & 5 deletions R/chart.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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."))
}

Expand Down Expand Up @@ -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){

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion R/chartId.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
#'
Expand Down
4 changes: 2 additions & 2 deletions R/command.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
26 changes: 15 additions & 11 deletions R/datasheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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)
#' }
#'
Expand Down
21 changes: 8 additions & 13 deletions R/datasheetSpatRaster.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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)
#'
Expand Down
20 changes: 20 additions & 0 deletions R/deleteLibrary.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions R/folder.R
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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
Expand All @@ -78,18 +78,18 @@ 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 ",
parentFolder,
". 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.")
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion R/folderId.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion R/name.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 9a513e2

Please sign in to comment.