|
1 |
| - |
| 1 | +#' Create an object representing an ML studio workspace |
| 2 | +#' |
| 3 | +#' Create an object that mediates access to a ML studio workspace. This does |
| 4 | +#' not actually create an ML studio workspace, it has to exist already. |
| 5 | +#' |
| 6 | +#' @param id Workspace id from ML studio -> settings -> workspace id |
| 7 | +#' @param authorization.token Authorization token from ML studio -> settings -> authorization.tokens |
| 8 | +#' |
| 9 | +#' @export |
| 10 | +#' @seealso \code{\link{datasets}}, \code{\link{experiments}} |
| 11 | +#' |
| 12 | +#' @return A Workspace object with the following user-accessible elements: |
| 13 | +#' \describe{ |
| 14 | +#' \item{experiments, example.experiments, user.experiments}{Collection of experiments in workspace, optionally filtered for example or user experiments} |
| 15 | +#' \item{datasets, example.datasets, user.datasets}{Collection of datasets in workspace, optionally filtered for example or user datasets} |
| 16 | +#'} |
| 17 | +#' @examples |
| 18 | +#' |
| 19 | +#' \dontrun{ |
| 20 | +#' # provide id and auth token from ML studio -> settings |
| 21 | +#' workspace(id, authorization.token) |
| 22 | +#' } |
2 | 23 | workspace =
|
3 | 24 | function(id, authorization.token)
|
4 | 25 | Workspace$new(id, authorization.token)
|
5 | 26 |
|
| 27 | + |
| 28 | + |
| 29 | +#' Extract datasets from experiments |
| 30 | +#' |
| 31 | +#' Extract datasets from experiments |
| 32 | +#' |
| 33 | +#' @param workspace workspace object, as returned by \code{\link{workspace}} |
| 34 | +#' |
| 35 | +#' @param x Experiment from which to extract a dataset |
| 36 | +#' @param node Node id |
| 37 | +#' @param port Port name |
| 38 | +#' @param data.type Format of intermediate data set |
| 39 | +#' |
| 40 | +#' @return A remote dataset |
| 41 | +#' @export |
| 42 | +#' |
| 43 | +#' @family dataset functions |
| 44 | + |
6 | 45 | datasets = function(workspace) private(workspace)$datasets
|
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +#' Extract experiments from Azure ML studio |
| 51 | +#' |
| 52 | +#' @inheritParams datasets |
| 53 | +#' |
| 54 | +#' @export |
| 55 | +#' @family experiment functions |
7 | 56 | experiments = function(workspace) private(workspace)$experiments
|
8 | 57 |
|
| 58 | + |
| 59 | + |
| 60 | +#' Convert Dataset to data.frame |
| 61 | +#' |
| 62 | +#' @param x Dataset to convert |
| 63 | +#' @param row.names Unused for now, needed for consistency with generic |
| 64 | +#' @param optional Unused for now, needed for consistency with generic |
| 65 | +#' @param \dots Unused for now, needed for consistency with generic |
| 66 | +#' |
| 67 | +#' @export |
| 68 | +#' @family dataset functions |
| 69 | +#' |
| 70 | +#' @return A data frame with the same contents as the dataset |
| 71 | +#' |
| 72 | +#' @examples |
| 73 | +#' |
| 74 | +#' \dontrun{ |
| 75 | +#' ws = workspace(id, authorization.token) |
| 76 | +#' as.data.frame(ws$datasets[[1]]) |
| 77 | +#' } |
| 78 | + |
9 | 79 | as.data.frame.Dataset = function(x, row.names = NULL, optional = FALSE, ...) private(x)$as.data.frame()
|
10 | 80 |
|
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +#' Access experiment or dataset by index or name/id |
| 85 | +#' |
| 86 | +#' Access individual experiments or datasets in a workspace by index or by name for datasets, id for experiments |
| 87 | +#' |
| 88 | +#' Both names and ids can be obtained with the function names applied to the experiments or datasets, which are elements of the a workspace object. |
| 89 | + |
| 90 | +#' @param x The experiments or datasets slots of a Workspace object |
| 91 | +#' @param i The index of the dataset or experiment |
| 92 | +#' @param name The name of the dataset |
| 93 | +#' @param id The id of the experiment |
| 94 | + |
| 95 | +#' @export |
| 96 | +#' @family dataset functions |
| 97 | + |
| 98 | +#' @return A dataset or experiment object |
| 99 | + |
| 100 | +#' @examples |
| 101 | +#' \dontrun{ |
| 102 | +#' # provide id and auth token from ML studio -> settings |
| 103 | +#' ws = workspace(id, authorization.token) |
| 104 | +#' experiments(ws)[[1]] |
| 105 | +#' datasets(ws)[[1]] |
| 106 | +#' # name from ML studio ->datasets -> my datasets or samples -> name or |
| 107 | +#' # names(ws$datsets) |
| 108 | +#' datasets(ws)[[name]] |
| 109 | +#' # id from ML studio -> experiments -> my datasets or samples -> name |
| 110 | +#' experiments(ws)[[id]] |
| 111 | +#' } |
| 112 | + |
11 | 113 | `[[.Datasets` = function(x, i) private(x)$get.item(i)
|
12 | 114 |
|
| 115 | + |
| 116 | +#' Convert Datsets object to list |
| 117 | +#' |
| 118 | +#' @export |
| 119 | +#' @family dataset functions |
| 120 | +#' |
| 121 | +#' @return A list of datasets |
13 | 122 | as.list.Datasets =
|
14 | 123 | function(x, ...) {
|
15 | 124 | y = private(x)$get.datasets()
|
16 | 125 | setNames(y, unlist(map(as.list(y), "Name")))}
|
17 | 126 |
|
| 127 | + |
| 128 | +#' Return the names of available experiments or datasets. |
| 129 | +#' |
| 130 | +#' %% ~~ A concise (1-5 lines) description of what the function does. ~~ |
| 131 | +#' |
| 132 | +#' In the case of Experiments, the names are actually experiment ids. |
| 133 | +#' |
| 134 | +#' @param x Collection of experiments or datasets to extract names from |
| 135 | +#' |
| 136 | +#' @export |
| 137 | +#' @family dataset functions |
| 138 | +#' @return A character vector. |
| 139 | +#' |
| 140 | +#' @examples |
| 141 | +#' |
| 142 | +#' \dontrun{ |
| 143 | +#' ws = workspace(id, authorization.token) |
| 144 | +#' names(experiments(ws)) |
| 145 | +#' names(datasets(ws)) |
| 146 | +#' } |
| 147 | + |
18 | 148 | names.Datasets = function(x) names(as.list(x))
|
19 | 149 |
|
| 150 | + |
| 151 | + |
| 152 | +#' @export |
| 153 | +#' @family dataset functions |
20 | 154 | `[[.Experiments` = function(x, i) private(x)$get.item(i)
|
21 | 155 |
|
| 156 | + |
| 157 | + |
| 158 | +#' Extract datasets from experiments |
| 159 | +#' |
| 160 | +#' Extract datasets from experiments |
| 161 | +#' |
| 162 | +#' |
| 163 | +#' @param x Experiment from which to extract a dataset |
| 164 | +#' @param node Node id |
| 165 | +#' @param port Port name |
| 166 | +#' @param data.type Format of intermediate data set |
| 167 | +#' @return A remote dataset |
| 168 | +#' |
| 169 | +#' @export dataset |
| 170 | +#' @family experiment functions |
| 171 | + |
22 | 172 | dataset =
|
23 | 173 | function(x, node, port, data.type) {
|
24 | 174 | private(x)$get.intermediate.dataset(node, port, data.type)}
|
25 | 175 |
|
| 176 | + |
| 177 | +#' Convert Collection of Datasets and Experiments to lists |
| 178 | +#' |
| 179 | +#' |
| 180 | +#' |
| 181 | +#' @param x The object to convert to a list |
| 182 | +#' @param \dots Unused, just for compatibility with generic |
| 183 | +#' |
| 184 | +#' @export |
| 185 | +#' @return A Dataset or Experiment object |
| 186 | +#' @family experiment functions |
| 187 | + |
| 188 | +#' @examples |
| 189 | +#' |
| 190 | +#' \dontrun{ |
| 191 | +#' ws = workspace(id, authorization.token) |
| 192 | +#' as.list(experiments(ws)) |
| 193 | +#' as.list(datasets(ws)) |
| 194 | +#' } |
| 195 | + |
26 | 196 | as.list.Experiments =
|
27 | 197 | function(x, ...) {
|
28 | 198 | y = private(x)$get.experiments()
|
29 | 199 | setNames(y, unlist(map(as.list(y), "ExperimentId")))}
|
30 | 200 |
|
| 201 | +#' @export |
| 202 | +#' @family experiment functions |
31 | 203 | names.Experiments = function(x) names(as.list(x))
|
32 | 204 |
|
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | + |
| 217 | +#' Create new remote dataset |
| 218 | +#' |
| 219 | +#' Create a new remote dataset from a dataframe or serialized data/ |
| 220 | +#' |
| 221 | +#' |
| 222 | +#' @param data Either a data frame or serialized data. |
| 223 | +#' @param workspace The workspace where to create the remote dataset |
| 224 | +#' @param data.type The format of \code{data} or to be used to serialize it. |
| 225 | +#' @param name A unique name for the data set within a workspace |
| 226 | +#' @param description An extended description for the dataset |
| 227 | +#' @return A remote dataset object. Can be transformed into a data frame with |
| 228 | +#' \code{as.data.frame} or updated with \code{update} |
| 229 | +#' @examples |
| 230 | +#' |
| 231 | +#' \dontrun{ |
| 232 | +#' ws = workspace(workspace, authorization.token) |
| 233 | +#' create(iris3, ws, "GenericCSV", "iris3", "Iris three class data set") |
| 234 | +#' } |
| 235 | +#' @export create |
33 | 236 | create =
|
34 | 237 | function(data, workspace, data.type, name, description)
|
35 | 238 | workspace$datasets$add(data, data.type, name, description)
|
36 | 239 |
|
| 240 | + |
| 241 | + |
| 242 | + |
| 243 | + |
| 244 | +#' Update and existing remote data set |
| 245 | +#' |
| 246 | +#' |
| 247 | +#' Arguments set to NULL are construed as "leave unchanged". |
| 248 | +#' |
| 249 | +#' @param x A remote dataset object as returned by \code{create} or extracted |
| 250 | +#' from a workspace experiments field with the bracket operator/ |
| 251 | +#' @param data A data frame or serialized data |
| 252 | +#' @param data.type The format of \code{data} or to be used to serialize it. |
| 253 | +#' @param name A unique name for the dataset |
| 254 | +#' @param description An extended description for the dataset |
| 255 | +#' @examples |
| 256 | +#' |
| 257 | +#' \dontrun{ |
| 258 | +#' ws = workspace(workspace, authorization.token) |
| 259 | +#' update(ws$user.datasets[[1]], iris3) |
| 260 | +#' } |
37 | 261 | update.Dataset =
|
38 | 262 | function(
|
39 | 263 | x,
|
|
0 commit comments