Skip to content

Commit

Permalink
Rename package to packages and remove installed='BASE' arg
Browse files Browse the repository at this point in the history
  • Loading branch information
katieb1 committed Nov 30, 2023
1 parent d6816ed commit bb67602
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 89 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Collate:
'internalWrappers.R'
'mergeDependencies.R'
'owner.R'
'package.R'
'packages.R'
'parentId.R'
'print.R'
'printCmd.R'
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export(installPackage)
export(mergeDependencies)
export(name)
export(owner)
export(package)
export(packages)
export(parentId)
export(printCmd)
export(progressBar)
Expand Down
4 changes: 2 additions & 2 deletions R/datasheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NULL
#'
#' @details
#' If \code{summary=TRUE} or \code{summary=NULL} and \code{name=NULL} a data.frame describing the
#' Datasheets is returned. If \code{optional=TRUE}, columns include: \code{scope}, \code{package},
#' Datasheets is returned. If \code{optional=TRUE}, columns include: \code{scope}, \code{packages},
#' \code{name}, \code{displayName}, \code{isSingle}, \code{isOutput}, \code{data}. data only displayed for
#' a SyncroSim \code{\link{Scenario}}. \code{dataInherited} and \code{dataSource} columns
#' added if a Scenario has dependencies. If \code{optional=FALSE}, columns include:
Expand Down Expand Up @@ -236,7 +236,7 @@ setMethod("datasheet",
n <- name[i]
if (!grepl("_", n, fixed = TRUE)) {
l = ssimLibrary(.filepath(ssimObject), summary=T)
p = l$value[l$property == "Package Name:"]
p = l$value[l$property == "Package Names:"][1] #TODO: test
n <- paste0(p, "_", n)
}

Expand Down
2 changes: 1 addition & 1 deletion R/datasheetRaster.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ setMethod("datasheetRaster", signature(ssimObject = "Scenario"), function(ssimOb

if (!grepl("_", datasheet, fixed = )) {
l = ssimLibrary(.filepath(ssimObject), summary=T)
p = l$value[l$property == "Package Name:"]
p = l$value[l$property == "Package Names:"][1]
datasheet <- paste0(p, "_", datasheet)
}

Expand Down
2 changes: 1 addition & 1 deletion R/datasheetSpatRaster.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ setMethod("datasheetSpatRaster", signature(ssimObject = "Scenario"), function(ss

if (!grepl("_", datasheet, fixed = )) {
l = ssimLibrary(.filepath(ssimObject), summary=T)
p = l$value[l$property == "Package Name:"]
p = l$value[l$property == "Package Names:"][1] #TODO: test
datasheet <- paste0(p, "_", datasheet)
}

Expand Down
4 changes: 2 additions & 2 deletions R/info.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Retrieves information about a library
#'
#' Retrieves some basic metadata about a SsimLibrary: Name, Owner, Last Modified,
#' Size, Read Only, Package Name, Package Description, Current Package Version,
#' Minimum Package Version, External input files, External output files,
#' Size, Read Only, Package Names, Package Description, Current Package Versions,
#' Minimum Package Versions, External input files, External output files,
#' Temporary files, Backup files.
#'
#' @param ssimLibrary \code{\link{SsimLibrary}} object
Expand Down
4 changes: 2 additions & 2 deletions R/installPackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ setMethod("installPackage", signature(session = "Session"), function(name, sessi
}
}
} else {
packages <- package(session)
if (is.element(name, packages$name)) {
pkgs <- packages(session)
if (is.element(name, pkgs$name)) {
tt <- (paste0("Package <", name, "> is already installed"))
} else {
tt <- command(args = list(install = name), session, program = "SyncroSim.PackageManager.exe")
Expand Down
12 changes: 1 addition & 11 deletions R/internalHelpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ backupEnabled <- function(path) {
deleteDatasheet <- function(x, datasheet, datasheets, cProj = NULL, cScn = NULL, cProjName = NULL, cScnName = NULL, out = list(), force) {
out <- list()
lib = ssimLibrary(.filepath(x), summary=T)
pkg = lib$value[lib$property == "Package Name:"]

for (j in seq(length.out = length(datasheet))) {
cName <- datasheet[j]

if (!grepl("_", cName, fixed = TRUE)) {
pkg = lib$value[lib$property == "Package Names:"][1]
cName <- paste0(pkg, "_", cName)
}

Expand Down Expand Up @@ -175,16 +175,6 @@ createCondaEnv <- function(libPath, currentPackages, session) {

message("Creating Conda environments. Please wait...")

# Check if Conda is installed
# tt <- command(list(conda = NULL, config = NULL), session)
# if (identical(tt, "No Conda configuration yet.")){
# tt <- command(list(setprop = NULL,
# lib = libPath,
# useconda = "no"), session)
# message("Conda must be installed to use Conda environments.")
# return(TRUE)
# }

# Check if environment needs to be created, create if doesn't exist yet
for (package in currentPackages) {
tt <- command(list(conda = NULL, createenv = NULL, pkg = package), session)
Expand Down
47 changes: 22 additions & 25 deletions R/package.R → R/packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ NULL

#' Installed or available packages
#'
#' Retrieves the packages installed or available for this version of SyncroSim.
#' Retrieves the packages installed or available in the current session if
#' called on a \code{\link{Session}} object, or the packages added to a
#' SyncroSim Library if called on a \code{\link{SsimLibrary}} object.
#'
#' @param ssimObject \code{\link{Session}} or
#' \code{\link{SsimLibrary}} object. If \code{NULL} (default), \code{session()}
#' will be used
#' @param installed logical or character. \code{TRUE} (default) to list installed packages,
#' \code{FALSE} to list available packages, and "BASE" to list installed base
#' packages
#' @param installed logical or character. \code{TRUE} (default) to list
#' installed packages or \code{FALSE} to list available packages on the server
#' @param listTemplates character. Name of a SyncroSim package. If not \code{NULL}
#' (default), then lists all templates available for that package. The package
#' must be installed in the current Session. Ignored if ssimObject is a
Expand All @@ -32,49 +33,45 @@ NULL
#' myLibrary <- ssimLibrary(name = myLibraryName, session = mySession)
#'
#' # List all installed packages
#' package(mySession)
#' packages(mySession)
#'
#' # List all the installed base packages
#' package(installed = "BASE")
#' packages(installed = "BASE")
#'
#' # List all available packages on the server (including currently installed)
#' package(installed = FALSE)
#' packages(installed = FALSE)
#'
#' # Check the package you're SsimLibrary is currently using
#' package(myLibrary)
#' # Check the package(s) in your SsimLibrary
#' packages(myLibrary)
#'
#' # Check the templates available for an installed package
#' installPackage("helloworldSpatial")
#' package(listTemplates = "helloworldSpatial")
#' packages(listTemplates = "helloworldSpatial")
#' }
#'
#' @export
setGeneric("package", function(ssimObject = NULL, installed = TRUE, listTemplates = NULL) standardGeneric("package"))
setGeneric("packages", function(ssimObject = NULL, installed = TRUE, listTemplates = NULL) standardGeneric("packages"))

#' @rdname package
setMethod("package", signature(ssimObject = "character"), function(ssimObject, installed = TRUE, listTemplates) {
#' @rdname packages
setMethod("packages", signature(ssimObject = "character"), function(ssimObject, installed = TRUE, listTemplates) {
return(SyncroSimNotFound(ssimObject, installed))
})

#' @rdname package
setMethod("package", signature(ssimObject = "missingOrNULL"), function(ssimObject, installed = TRUE, listTemplates) {
#' @rdname packages
setMethod("packages", signature(ssimObject = "missingOrNULL"), function(ssimObject, installed = TRUE, listTemplates) {
ssimObject <- .session()
return(package(ssimObject, installed, listTemplates))
return(packages(ssimObject, installed, listTemplates))
})

#' @rdname package
setMethod("package", signature(ssimObject = "Session"), function(ssimObject, installed = TRUE, listTemplates) {
#' @rdname packages
setMethod("packages", signature(ssimObject = "Session"), function(ssimObject, installed = TRUE, listTemplates) {
if (is.null(listTemplates)) {
arg <- "installed"

if (installed == FALSE) {
arg <- "available"
}

if (installed == "BASE") {
arg <- "basepkgs"
}

if (is.logical(installed)) {
tt <- command(c(arg), ssimObject, program = "SyncroSim.PackageManager.exe")

Expand Down Expand Up @@ -119,11 +116,11 @@ setMethod("package", signature(ssimObject = "Session"), function(ssimObject, ins
}
})

#' @rdname package
setMethod("package", signature(ssimObject = "SsimLibrary"), function(ssimObject) {
#' @rdname packages
setMethod("packages", signature(ssimObject = "SsimLibrary"), function(ssimObject) {
oInf <- info(ssimObject)
property <- NULL
out <- data.frame(name = subset(oInf, property == "Package Name:")$value)
out <- data.frame(name = subset(oInf, property == "Package Names:")$value)
out$description <- subset(oInf, property == "Package Description:")$value
out$version <- subset(oInf, property == "Current Package Version:")$value
return(out)
Expand Down
2 changes: 1 addition & 1 deletion R/saveDatasheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ setMethod("saveDatasheet", signature(ssimObject = "SsimObject"), function(ssimOb

if (!grepl("_", name, fixed = )) {
l = ssimLibrary(.filepath(ssimObject), summary=T)
p = l$value[l$property == "Package Name:"]
p = l$value[l$property == "Package Name:"][1] #TODO: test
name <- paste0(p, "_", name)
}

Expand Down
5 changes: 1 addition & 4 deletions R/session.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ setMethod(f = "initialize", signature = "Session", definition = function(.Object
#' version(mySession)
#'
#' # Data frame of the packages installed with this version of SyncroSim
#' package(mySession)
#'
#' # Data frame of the base packages installed with this version of SyncroSim
#' package(mySession, installed = "BASE")
#' packages(mySession)
#'
#' # Set a new SyncroSim Session for the SyncroSim Project
#' session(myProject) <- session(x = filepath(session(myProject)))
Expand Down
12 changes: 6 additions & 6 deletions R/ssimLibrary.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ setMethod(
stop("A library name is required.")
}

packageOptions <- package(session, installed = "BASE")
packageOptions <- packages(session, installed = TRUE)

if (nrow(packageOptions) == 0) {
stop("No base packages are installed. Use installPackage() to install a package.")
stop("No packages are installed. Use installPackage() to install a package.")
}

if (identical(basename(name), name)) {
Expand All @@ -62,7 +62,7 @@ setMethod(
}

if (!is.element(package, packageOptions$name)) {
stop(paste(package, "not a base package. Use package(installed = \"BASE\") to see options."))
stop(paste(package, "not currently installed. Use package(installed = TRUE) to see options."))
}

pathBits <- strsplit(path, "/")[[1]]
Expand Down Expand Up @@ -99,7 +99,7 @@ setMethod(
baseTemplateExists <- baseTemplate %in% baseTempsDataframe$Name

if (!baseTemplateExists & !is.null(addon)) {
allPackageOptions <- package(session)
allPackageOptions <- packages(session)
args <- list(list = NULL, templates = NULL,
package = allPackageOptions$name[allPackageOptions$name == addon],
csv = NULL)
Expand Down Expand Up @@ -203,10 +203,10 @@ setMethod(
}

if (!exists("packageOptions")) {
packageOptions <- package(session, installed = "BASE")
packageOptions <- packages(session, installed = TRUE)
}
expectedPackage <- packageOptions$name[packageOptions$name == package]
if (!grepl(expectedPackage, tt$value[tt$property == "Package Name:"])) {
if (!grepl(expectedPackage, tt$value[tt$property == "Package Names:"])) { #TODO: this is probably broken now
stop(paste0("A library of that name and a different package type ", tt$value[tt$property == "Name:"], " already exists."))
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/uninstallPackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ setMethod("uninstallPackage", signature(session = "missingOrNULL"), function(nam

#' @rdname uninstallPackage
setMethod("uninstallPackage", signature(session = "Session"), function(name, session, force) {
installed <- package(session)
installed <- packages(session)
success <- FALSE

if (!is.element(name, installed$name)) {
Expand Down
2 changes: 1 addition & 1 deletion R/updatePackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ setMethod("updatePackage", signature(session = "Session"), function(name, sessio
return(invisible(success))
}
} else {
installed <- package(session)
installed <- packages(session)

if (!is.element(name, installed$name)) {
message(paste(name, ": The package is not installed."))
Expand Down
2 changes: 1 addition & 1 deletion R/useConda.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ setReplaceMethod(

tt <- command(list(setprop = NULL, lib = .filepath(ssimObject), useconda = "yes"), .session(ssimObject))

currentPackages <- package(ssimObject)$name
currentPackages <- packages(ssimObject)$name
}

createCondaEnv(.filepath(ssimObject), currentPackages, .session(ssimObject))
Expand Down
2 changes: 1 addition & 1 deletion man/datasheet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/info.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bb67602

Please sign in to comment.