Skip to content

Commit

Permalink
Remove enableAddon, disableAddon, add addPackage, removePackage
Browse files Browse the repository at this point in the history
  • Loading branch information
katieb1 committed Nov 30, 2023
1 parent 302d743 commit d6816ed
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 287 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Suggests:
SystemRequirements: SyncroSim (>=2.3.10)
Collate:
'AAAClassDefinitions.R'
'addPackage.R'
'addRow.R'
'autogentags.R'
'backup.R'
Expand All @@ -59,8 +60,6 @@ Collate:
'delete.R'
'dependency.R'
'description.R'
'disableAddon.R'
'enableAddon.R'
'filepath.R'
'folder.R'
'folderId.R'
Expand All @@ -86,6 +85,7 @@ Collate:
'printCmd.R'
'published.R'
'readOnly.R'
'removePackage.R'
'rsyncrosim.R'
'run.R'
'runLog.R'
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export(Scenario)
export(Session)
export(SsimLibrary)
export(addBreakpoint)
export(addPackage)
export(addRow)
export(autogentags)
export(backup)
Expand All @@ -33,8 +34,6 @@ export(delete)
export(deleteBreakpoint)
export(dependency)
export(description)
export(disableAddon)
export(enableAddon)
export(filepath)
export(folder)
export(folderId)
Expand All @@ -53,6 +52,7 @@ export(project)
export(projectId)
export(published)
export(readOnly)
export(removePackage)
export(run)
export(runLog)
export(runtimeInputFolder)
Expand Down
73 changes: 73 additions & 0 deletions R/addPackage.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (c) 2023 Apex Resource Management Solution Ltd. (ApexRMS). All rights reserved.
# MIT License
#' @include AAAClassDefinitions.R
NULL

#' Add SyncroSim package(s)
#'
#' Adds package(s) to a \code{\link{SsimLibrary}}.
#'
#' @param ssimLibrary \code{\link{SsimLibrary}} object
#' @param name character string or vector of package name(s)
#'
#' @return
#' Invisibly returns \code{TRUE} upon success (i.e.successful addition
#' of the package) or \code{FALSE} upon failure.
#'
#' @seealso
#' \code{\link{packages}}
#'
#' @examples
#' \donttest{
#' # Install "stsim" SyncroSim package
#' installPackage("stsim")
#'
#' # Specify file path and name of new SsimLibrary
#' myLibraryName <- file.path(tempdir(), "testlib")
#'
#' # Set up a SyncroSim Session, SsimLibrary, and Project
#' mySession <- session()
#' myLibrary <- ssimLibrary(name = myLibraryName, session = mySession,
#' package = "stsim")
#'
#' # Add package
#' addPackage(myLibrary, c("stsimsf"))
#' packages(myLibrary)
#'
#' # Remove package
#' removePackage(myLibrary, c("stsimsf"))
#' packages(myLibrary)
#' }
#'
#' @export
setGeneric("addPackage", function(ssimLibrary, name) standardGeneric("addPackage"))

#' @rdname addPackage
setMethod("addPackage", signature(ssimLibrary = "character"), function(ssimLibrary, name) {
return(SyncroSimNotFound(ssimLibrary))
})

#' @rdname addPackage
setMethod("addPackage", signature(ssimLibrary = "SsimLibrary"), function(ssimLibrary, name) {
cAdds <- packages(ssimLibrary)
retList <- list()
for (i in seq(length.out = length(name))) {
cVal <- name[i]
if (!is.element(cVal, cAdds$name)) {
print(paste0("Warning - ", cVal, " is not among the available packages: ", paste(cAdds$name, collapse = ",")))
retList[[cVal]] <- FALSE
next
}

tt <- command(list(add = NULL, package = NULL, lib = .filepath(ssimLibrary), pkg = cVal), .session(ssimLibrary))
if (tt == "saved"){
message(paste0("Package <", cVal, "> added"))
retList[[cVal]] <- TRUE
} else {
message(tt)
retList[[cVal]] <- FALSE
}
}

return(invisible(retList))
})
81 changes: 0 additions & 81 deletions R/disableAddon.R

This file was deleted.

80 changes: 0 additions & 80 deletions R/enableAddon.R

This file was deleted.

74 changes: 74 additions & 0 deletions R/removePackage.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright (c) 2023 Apex Resource Management Solution Ltd. (ApexRMS). All rights reserved.
# MIT License
#' @include AAAClassDefinitions.R
NULL

#' Removes SyncroSim package(s)
#'
#' Removes package(s) from a \code{\link{SsimLibrary}}.
#'
#' @param ssimLibrary \code{\link{SsimLibrary}} object
#' @param name character string or vector of package name(s)
#'
#' @return
#' This function invisibly returns \code{TRUE} upon success (i.e.successful
#' removal of the package) or \code{FALSE} upon failure.
#'
#' @seealso
#' \code{\link{packages}}
#'
#' @examples
#' \donttest{
#' # Install "stsim" SyncroSim package
#' installPackage("stsim")
#'
#' # Specify file path and name of new SsimLibrary
#' myLibraryName <- file.path(tempdir(), "testlib")
#'
#' # Set up a SyncroSim Session, SsimLibrary, and Project
#' mySession <- session()
#' myLibrary <- ssimLibrary(name = myLibraryName, session = mySession,
#' package = "stsim")
#'
#' # Add package
#' addPackage(myLibrary, c("stsimsf"))
#' packages(myLibrary)
#'
#' # Remove package
#' removePackage(myLibrary, c("stsimsf"))
#' packages(myLibrary)
#' }
#'
#' @export
setGeneric("removePackage", function(ssimLibrary, name) standardGeneric("removePackage"))

#' @rdname removePackage
setMethod("removePackage", signature(ssimLibrary = "character"), function(ssimLibrary, name) {
return(SyncroSimNotFound(ssimLibrary))
})

#' @rdname removePackage
setMethod("removePackage", signature(ssimLibrary = "SsimLibrary"), function(ssimLibrary, name) {
cAdds <- subset(addon(ssimLibrary))
retList <- list()

for (i in seq(length.out = length(name))) {
cVal <- name[i]
if (!is.element(cVal, cAdds$name)) {
print(paste0("Warning - ", cVal, " is not among the available packages: ", paste(cAdds$name, collapse = ",")))
retList[[cVal]] <- FALSE
next
}

tt <- command(list(remove = NULL, package = NULL, force = NULL, lib = .filepath(ssimLibrary), pkg = cVal), .session(ssimLibrary))
if (tt == "saved"){
message(paste0("Package <", cVal, "> removed"))
retList[[cVal]] <- TRUE
} else {
message(tt)
retList[[cVal]] <- FALSE
}
}

return(invisible(retList))
})
Loading

0 comments on commit d6816ed

Please sign in to comment.