-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMetadata.R
More file actions
133 lines (125 loc) · 4.79 KB
/
Metadata.R
File metadata and controls
133 lines (125 loc) · 4.79 KB
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
# MIT License
#
# Copyright (c) 2017-2025 TileDB Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
##' Test if TileDB Array has Metadata
##'
##' @param arr A TileDB Array object
##' @param key A character value describing a metadata key
##' @return A logical value indicating if the given key exists in the
##' metadata of the given array
##' @export
tiledb_has_metadata <- function(arr, key) {
stopifnot(
`Argument 'arr' must be a (dense or sparse) TileDB array` = .isArray(arr),
`Argument 'key' must be a scalar character` = is.scalar(key, "character"),
`Array must be open for reading to access metadata` = libtiledb_array_is_open_for_reading(arr@ptr)
)
res <- libtiledb_array_get_metadata_list(arr@ptr)
key %in% names(res)
}
##' Return count of TileDB Array Metadata objects
##'
##' @param arr A TileDB Array object
##' @return A integer variable with the number of Metadata objects
##' @export
tiledb_num_metadata <- function(arr) {
stopifnot(
`Argument 'arr' must be a (dense or sparse) TileDB array` = .isArray(arr),
`Array must be open for reading to access metadata` = libtiledb_array_is_open_for_reading(arr@ptr)
)
libtiledb_array_get_metadata_num(arr@ptr)
}
##' Return a TileDB Array Metadata object given by key
##'
##' @param arr A TileDB Array object
##' @param key A character value describing a metadata key
##' @return A object stored in the Metadata under the given key,
##' or \sQuote{NULL} if none found.
##' @export
tiledb_get_metadata <- function(arr, key) {
stopifnot(
`Argument 'arr' must be a (dense or sparse) TileDB array` = .isArray(arr),
`Array must be open for reading to access metadata` = libtiledb_array_is_open_for_reading(arr@ptr)
)
res <- libtiledb_array_get_metadata_list(arr@ptr)
if (key %in% names(res)) {
res[[key]]
} else {
NULL
}
}
##' Store an object in TileDB Array Metadata under given key
##'
##' @param arr A TileDB Array object
##' @param key A character value describing a metadata key
##' @param val An object to be stored
##' @return A boolean value indicating success
##' @export
tiledb_put_metadata <- function(arr, key, val) {
stopifnot(
`Argument must be a (dense or sparse) TileDB array.` = .isArray(arr),
`Array is not open for writing.` = libtiledb_array_is_open_for_writing(arr@ptr)
)
libtiledb_array_put_metadata(arr@ptr, key, val)
}
##' Return all TileDB Array Metadata objects as a named list
##'
##' @param arr A TileDB Array object
##' @return A named list with all Metadata objects indexed by the given key
##' @export
tiledb_get_all_metadata <- function(arr) {
stopifnot(
`Argument 'arr' must be a (dense or sparse) TileDB array` = .isArray(arr),
`Array must be open for reading to access metadata` = libtiledb_array_is_open_for_reading(arr@ptr)
)
res <- libtiledb_array_get_metadata_list(arr@ptr)
class(res) <- "tiledb_metadata"
res
}
##' Print a TileDB Array Metadata object
##'
##' @param x A TileDB array object
##' @param width Optional display width, defaults to NULL
##' @param ... Optional method arguments, currently unused
##' @return The array object, invisibly
##' @export
##' @method print tiledb_metadata
print.tiledb_metadata <- function(x, width = NULL, ...) {
nm <- names(x)
for (i in 1:length(nm)) {
cat(nm[i], ":\t", format(x[i]), "\n", sep = "")
}
invisible(x)
}
##' Delete a TileDB Array Metadata object given by key
##'
##' @param arr A TileDB Array object
##' @param key A character value describing a metadata key
##' @return A boolean indicating success
##' @export
tiledb_delete_metadata <- function(arr, key) {
stopifnot(
`Argument must be a (dense or sparse) TileDB array.` = .isArray(arr),
`Array is not open for writing.` = libtiledb_array_is_open_for_writing(arr@ptr)
)
libtiledb_array_delete_metadata(arr@ptr, key)
TRUE # we get NULL from C++
}