/
package.R
136 lines (125 loc) · 4.74 KB
/
package.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Copyright (c) 2024 Apex Resource Management Solution Ltd. (ApexRMS). All rights reserved.
# MIT License
#' @include AAAClassDefinitions.R
NULL
#' Installed or available packages
#'
#' Retrieves the packages installed or available for this version of SyncroSim.
#'
#' @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 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
#' \code{\link{SsimLibrary}} object
#'
#' @return
#' Returns a \code{data.frame} of packages installed or templates available
#' for a specified package.
#'
#' @examples
#' \donttest{
#' # Set the file path and name of the new SsimLibrary
#' myLibraryName <- file.path(tempdir(),"testlib")
#'
#' # Set the SyncroSim Session and SsimLibrary
#' mySession <- session()
#' myLibrary <- ssimLibrary(name = myLibraryName, session = mySession)
#'
#' # List all installed packages
#' package(mySession)
#'
#' # List all the installed base packages
#' package(installed = "BASE")
#'
#' # List all available packages on the server (including currently installed)
#' package(installed = FALSE)
#'
#' # Check the package you're SsimLibrary is currently using
#' package(myLibrary)
#'
#' # Check the templates available for an installed package
#' addPackage("helloworldSpatial")
#' package(listTemplates = "helloworldSpatial")
#' }
#'
#' @export
setGeneric("package", function(ssimObject = NULL, installed = TRUE, listTemplates = NULL) standardGeneric("package"))
#' @rdname package
setMethod("package", signature(ssimObject = "character"), function(ssimObject, installed = TRUE, listTemplates) {
return(SyncroSimNotFound(ssimObject, installed))
})
#' @rdname package
setMethod("package", signature(ssimObject = "missingOrNULL"), function(ssimObject, installed = TRUE, listTemplates) {
ssimObject <- .session()
return(package(ssimObject, installed, listTemplates))
})
#' @rdname package
setMethod("package", 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")
if (tt[1] == "saved") {
out <- data.frame(name = NA, displayName = NA, version = NA)
out <- subset(out, !is.na(name))
} else if (grepl("The remote name could not be resolved", tt[1])) {
out <- "Could not connect to the package server."
} else {
out <- .dataframeFromSSim(tt, localNames = TRUE, csv=FALSE)
}
drops <- c("x")
out <- out[ , !(names(out) %in% drops)]
return(out)
} else {
tt <- command(c("list", arg, "csv"), ssimObject)
out <- .dataframeFromSSim(tt, localNames = TRUE, csv = FALSE)
drops <- c("x")
out <- out[ , !(names(out) %in% drops)]
return(out)
}
} else {
if (is.character(listTemplates)) {
# Make sure package is installed
pkgList <- command(c("installed"), ssimObject,
program = "SyncroSim.PackageManager.exe")
pkgDf <- .dataframeFromSSim(pkgList,
localNames = TRUE,
csv = FALSE)
if (listTemplates %in% pkgDf$name == FALSE) {
stop("SyncroSim package not installed")
}
# Retrieve list of templates
args <- list(list = NULL, templates = NULL, noheaders = NULL,
package = listTemplates)
tt <- command(args, program = "SyncroSim.Console.exe")
out <- .dataframeFromSSim(tt,
colNames =c("name", "displayName", "installed"),
csv = F)
drops <- c("x")
out <- out[ , !(names(out) %in% drops)]
return(out)
} else {
stop("listTemplates must be a character name of a SyncroSim Package")
}
}
})
#' @rdname package
setMethod("package", signature(ssimObject = "SsimLibrary"), function(ssimObject) {
oInf <- info(ssimObject)
property <- NULL
out <- data.frame(name = subset(oInf, property == "Package Name:")$value)
out$description <- subset(oInf, property == "Package Description:")$value
out$version <- subset(oInf, property == "Current Package Version:")$value
return(out)
})