From d9830bd1585d8f79b01497bc3963a4d30515c322 Mon Sep 17 00:00:00 2001 From: katieb1 Date: Fri, 1 Dec 2023 16:57:30 -0800 Subject: [PATCH] Tested and fixed addPackage & removePackage --- R/addPackage.R | 17 +++++++++++++---- R/packages.R | 2 +- R/removePackage.R | 7 ++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/R/addPackage.R b/R/addPackage.R index 15bd5d31..b26cead1 100644 --- a/R/addPackage.R +++ b/R/addPackage.R @@ -49,17 +49,26 @@ setMethod("addPackage", signature(ssimLibrary = "character"), function(ssimLibra #' @rdname addPackage setMethod("addPackage", signature(ssimLibrary = "SsimLibrary"), function(ssimLibrary, name) { - cAdds <- packages(ssimLibrary) + sessionPkgs <- packages(.session(ssimLibrary)) + libraryPkgs <- 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 = ","))) + if (is.element(cVal, libraryPkgs$name)){ + print(paste0(cVal, " has already been added to the ssimLibrary")) + retList[[cVal]] <- FALSE + next + } + + if (!is.element(cVal, sessionPkgs$name)) { + print(paste0("Warning - ", cVal, " is not among the available packages: ", + paste(sessionPkgs$name, collapse = ","))) retList[[cVal]] <- FALSE next } - tt <- command(list(add = NULL, package = NULL, lib = .filepath(ssimLibrary), pkg = cVal), .session(ssimLibrary)) + 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 diff --git a/R/packages.R b/R/packages.R index 78097771..ebd3fc4c 100644 --- a/R/packages.R +++ b/R/packages.R @@ -123,7 +123,7 @@ setMethod("packages", signature(ssimObject = "SsimLibrary"), function(ssimObject #TODO: change to --packages when update to next version of SyncroSim v3 args <- list(list = NULL, pkgvers = NULL, lib = filepath(ssimObject), csv = NULL) tt <- command(args, program = "SyncroSim.Console.exe", - progName=filepath(session(ssimObject))) + progName=filepath(.session(ssimObject))) out <- .dataframeFromSSim(tt, csv = T) return(out) diff --git a/R/removePackage.R b/R/removePackage.R index d5bab518..8cbeec70 100644 --- a/R/removePackage.R +++ b/R/removePackage.R @@ -49,13 +49,14 @@ setMethod("removePackage", signature(ssimLibrary = "character"), function(ssimLi #' @rdname removePackage setMethod("removePackage", signature(ssimLibrary = "SsimLibrary"), function(ssimLibrary, name) { - cAdds <- subset(addon(ssimLibrary)) + libraryPkgs <- subset(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 = ","))) + if (!is.element(cVal, libraryPkgs$name)) { + print(paste0("Warning - ", cVal, " is not among the available packages: ", + paste(libraryPkgs$name, collapse = ","))) retList[[cVal]] <- FALSE next }