Skip to content

Commit

Permalink
neatens
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Oct 28, 2024
1 parent 1679531 commit 498e8e9
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 115 deletions.
26 changes: 14 additions & 12 deletions R/Array.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ tiledb_array_create <- function(uri, schema, encryption_key) { # , ctx = tiledb_
##' @return The TileDB Array object but opened for reading or writing
##' @importFrom methods .hasSlot
##' @export
tiledb_array_open <- function(arr,
type = if (tiledb_version(TRUE) >= "2.12.0") {
c("READ", "WRITE", "DELETE", "MODIFY_EXCLUSIVE")
} else {
c("READ", "WRITE")
}) {
tiledb_array_open <- function(
arr,
type = if (tiledb_version(TRUE) >= "2.12.0") {
c("READ", "WRITE", "DELETE", "MODIFY_EXCLUSIVE")
} else {
c("READ", "WRITE")
}) {
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr))
type <- match.arg(type)

Expand Down Expand Up @@ -234,12 +235,13 @@ tiledb_array_has_enumeration <- function(arr) {
##' @param nullable A boolean toggle whether the attribute is nullable
##' @return The value of the aggregation
##' @export
tiledb_array_apply_aggregate <- function(array, attrname,
operation = c(
"Count", "NullCount", "Min", "Max",
"Mean", "Sum"
),
nullable = TRUE) {
tiledb_array_apply_aggregate <- function(
array, attrname,
operation = c(
"Count", "NullCount", "Min", "Max",
"Mean", "Sum"
),
nullable = TRUE) {
stopifnot(
"The 'array' argument must be a TileDB Array object" = is(array, "tiledb_array"),
"The 'array' must be a sparse TileDB Array" = is.sparse(schema(array)),
Expand Down
32 changes: 17 additions & 15 deletions R/ArraySchema.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,19 @@ tiledb_array_schema.from_ptr <- function(ptr, arrptr = NULL) {
#' schema
#'
#' @export
tiledb_array_schema <- function(domain,
attrs,
cell_order = "COL_MAJOR",
tile_order = "COL_MAJOR",
sparse = FALSE,
coords_filter_list = NULL,
offsets_filter_list = NULL,
validity_filter_list = NULL,
capacity = 10000L,
allows_dups = FALSE,
enumerations = NULL,
ctx = tiledb_get_context()) {
tiledb_array_schema <- function(
domain,
attrs,
cell_order = "COL_MAJOR",
tile_order = "COL_MAJOR",
sparse = FALSE,
coords_filter_list = NULL,
offsets_filter_list = NULL,
validity_filter_list = NULL,
capacity = 10000L,
allows_dups = FALSE,
enumerations = NULL,
ctx = tiledb_get_context()) {
if (!missing(attrs) && length(attrs) != 0) {
is_attr <- function(obj) is(obj, "tiledb_attr")
if (is_attr(attrs)) { # if an attrs object given:
Expand Down Expand Up @@ -1006,9 +1007,10 @@ describe <- function(arr) {
#' or \code{ordered} (when \code{TRUE})
#' @param ctx Optional tiledb_ctx object
#' @export
tiledb_array_schema_set_enumeration_empty <- function(schema, attr, enum_name,
type_str = "ASCII", cell_val_num = NA_integer_,
ordered = FALSE, ctx = tiledb_get_context()) {
tiledb_array_schema_set_enumeration_empty <- function(
schema, attr, enum_name,
type_str = "ASCII", cell_val_num = NA_integer_,
ordered = FALSE, ctx = tiledb_get_context()) {
stopifnot(
"Argument 'schema' must be a 'tiledb_array_schema'" = is(schema, "tiledb_array_schema"),
"Argument 'attr' must be a 'tiledb_attribute'" = is(attr, "tiledb_attr"),
Expand Down
14 changes: 8 additions & 6 deletions R/ArraySchemaEvolution.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ tiledb_array_schema_evolution_array_evolve <- function(object, uri) {
#' context object is retrieved
#' @return The modified 'array_schema_evolution' object, invisibly
#' @export
tiledb_array_schema_evolution_add_enumeration <- function(object, name, enums, ordered = FALSE,
ctx = tiledb_get_context()) {
tiledb_array_schema_evolution_add_enumeration <- function(
object, name, enums, ordered = FALSE,
ctx = tiledb_get_context()) {
stopifnot(
"The first argument must be an Array Schema Evolution object" =
is(object, "tiledb_array_schema_evolution"),
Expand Down Expand Up @@ -179,10 +180,11 @@ tiledb_array_schema_evolution_add_enumeration_empty <- function(ase, enum_name,
#' @param ctx Optional tiledb_ctx object
#' @return The modified ArraySchemaEvolution object
#' @export
tiledb_array_schema_evolution_extend_enumeration <- function(ase, array, enum_name,
new_values, nullable = FALSE,
ordered = FALSE,
ctx = tiledb_get_context()) {
tiledb_array_schema_evolution_extend_enumeration <- function(
ase, array, enum_name,
new_values, nullable = FALSE,
ordered = FALSE,
ctx = tiledb_get_context()) {
stopifnot(
"Argument 'ase' must be an Array Schema Evolution object" =
is(ase, "tiledb_array_schema_evolution"),
Expand Down
15 changes: 8 additions & 7 deletions R/Attribute.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ tiledb_attr.from_ptr <- function(ptr) {
#'
#' @importFrom methods new
#' @export
tiledb_attr <- function(name,
type,
filter_list = tiledb_filter_list(),
ncells = 1,
nullable = FALSE,
enumeration = NULL,
ctx = tiledb_get_context()) {
tiledb_attr <- function(
name,
type,
filter_list = tiledb_filter_list(),
ncells = 1,
nullable = FALSE,
enumeration = NULL,
ctx = tiledb_get_context()) {
if (missing(name)) name <- ""
if (is.na(ncells)) ncells <- NA_integer_ # the specific NA for ints (as basic NA is bool)
stopifnot(
Expand Down
15 changes: 8 additions & 7 deletions R/DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@
##' all.equal(iris, newdf, check.attributes=FALSE) # extra attribute on query in newdf
##' all.equal(as.matrix(iris), as.matrix(newdf)) # also strips attribute
##' @export
fromDataFrame <- function(obj, uri, col_index = NULL, sparse = TRUE, allows_dups = sparse,
cell_order = "COL_MAJOR", tile_order = "COL_MAJOR", filter = "ZSTD",
capacity = 10000L, tile_domain = NULL, tile_extent = NULL,
mode = c("ingest", "schema_only", "append"), filter_list = NULL,
coords_filters = "ZSTD", offsets_filters = "ZSTD",
validity_filters = "RLE", debug = FALSE,
timestamps = as.POSIXct(double(), origin = "1970-01-01")) {
fromDataFrame <- function(
obj, uri, col_index = NULL, sparse = TRUE, allows_dups = sparse,
cell_order = "COL_MAJOR", tile_order = "COL_MAJOR", filter = "ZSTD",
capacity = 10000L, tile_domain = NULL, tile_extent = NULL,
mode = c("ingest", "schema_only", "append"), filter_list = NULL,
coords_filters = "ZSTD", offsets_filters = "ZSTD",
validity_filters = "RLE", debug = FALSE,
timestamps = as.POSIXct(double(), origin = "1970-01-01")) {
stopifnot(
"Argument 'obj' should be a 'data.frame' (or a related object)" = inherits(obj, "data.frame"),
"Argument 'uri' should be a character variable" = is.character(uri),
Expand Down
5 changes: 3 additions & 2 deletions R/Dim.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ tiledb_dim.from_ptr <- function(ptr) {
#'
#' @importFrom methods new
#' @export tiledb_dim
tiledb_dim <- function(name, domain, tile, type,
filter_list = tiledb_filter_list(), ctx = tiledb_get_context()) {
tiledb_dim <- function(
name, domain, tile, type,
filter_list = tiledb_filter_list(), ctx = tiledb_get_context()) {
stopifnot(
"Argument 'name' must be supplied when creating a dimension object" = !missing(name),
"Argument 'name' must be a scalar string when creating a dimension object" = is.scalar(name, "character"),
Expand Down
5 changes: 3 additions & 2 deletions R/Group.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ setClass("tiledb_group",
#' @param cfg (optional) A TileConfig object
#' @return A 'group' object
#' @export
tiledb_group <- function(uri, type = c("READ", "WRITE"),
ctx = tiledb_get_context(), cfg = NULL) {
tiledb_group <- function(
uri, type = c("READ", "WRITE"),
ctx = tiledb_get_context(), cfg = NULL) {
stopifnot(
"The 'ctx' argument must be a Context object" = is(ctx, "tiledb_ctx"),
"The 'uri' argument must be character" = is.character(uri),
Expand Down
9 changes: 5 additions & 4 deletions R/Matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
##' @return Null, invisibly.
##'
##' @export
fromMatrix <- function(obj,
uri,
filter = "ZSTD",
capacity = 10000L) {
fromMatrix <- function(
obj,
uri,
filter = "ZSTD",
capacity = 10000L) {
stopifnot(
`Argument 'obj' must be matrix object` = inherits(obj, "matrix"),
`Argument 'uri' must be character` = is.character(uri)
Expand Down
37 changes: 20 additions & 17 deletions R/Query.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ setClass("tiledb_query",
#' @param ctx (optional) A TileDB Ctx object
#' @return 'tiledb_query' object
#' @export tiledb_query
tiledb_query <- function(array,
type = if (tiledb_version(TRUE) >= "2.12.0") {
c("READ", "WRITE", "DELETE", "MODIFY_EXCLUSIVE")
} else {
c("READ", "WRITE")
},
ctx = tiledb_get_context()) {
tiledb_query <- function(
array,
type = if (tiledb_version(TRUE) >= "2.12.0") {
c("READ", "WRITE", "DELETE", "MODIFY_EXCLUSIVE")
} else {
c("READ", "WRITE")
},
ctx = tiledb_get_context()) {
stopifnot(`Argument 'arr' must be a tiledb_array object` = .isArray(array))
type <- match.arg(type)
array <- tiledb_array_open(array, type)
Expand All @@ -71,10 +72,11 @@ tiledb_query_type <- function(query) {
#' "COL_MAJOR", "ROW_MAJOR", "GLOBAL_ORDER", "UNORDERED")
#' @return The modified query object, invisibly
#' @export
tiledb_query_set_layout <- function(query, layout = c(
"COL_MAJOR", "ROW_MAJOR",
"GLOBAL_ORDER", "UNORDERED"
)) {
tiledb_query_set_layout <- function(
query, layout = c(
"COL_MAJOR", "ROW_MAJOR",
"GLOBAL_ORDER", "UNORDERED"
)) {
stopifnot(`Argument 'query' must be a tiledb_query object` = is(query, "tiledb_query"))
layout <- match.arg(layout)
libtiledb_query_set_layout(query@ptr, layout)
Expand Down Expand Up @@ -649,12 +651,13 @@ tiledb_query_ctx <- function(query) {
##' @param nullable A boolean toggle whether the attribute is nullable
##' @return The value of the aggregation
##' @export
tiledb_query_apply_aggregate <- function(query, attrname,
operation = c(
"Count", "NullCount", "Min", "Max",
"Mean", "Sum"
),
nullable = TRUE) {
tiledb_query_apply_aggregate <- function(
query, attrname,
operation = c(
"Count", "NullCount", "Min", "Max",
"Mean", "Sum"
),
nullable = TRUE) {
stopifnot(
"The 'query' argument must be a TileDB Query object" = is(query, "tiledb_query"),
"The 'attrname' argument must be character" = is.character(attrname),
Expand Down
13 changes: 7 additions & 6 deletions R/SparseMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@
##' }
##' @importFrom methods as
##' @export
fromSparseMatrix <- function(obj,
uri,
cell_order = "ROW_MAJOR",
tile_order = "ROW_MAJOR",
filter = "ZSTD",
capacity = 10000L) {
fromSparseMatrix <- function(
obj,
uri,
cell_order = "ROW_MAJOR",
tile_order = "ROW_MAJOR",
filter = "ZSTD",
capacity = 10000L) {
stopifnot(
`Argument 'obj' must be Matrix object` = inherits(obj, "Matrix"),
`Argument 'obj' must be sparse` = is(obj, "sparseMatrix"),
Expand Down
59 changes: 31 additions & 28 deletions R/TileDBArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,29 @@ setClass("tiledb_array",
#' @return tiledb_array object
#' @importFrom spdl set_level
#' @export
tiledb_array <- function(uri,
query_type = c("READ", "WRITE"),
is.sparse = NA,
attrs = character(),
extended = TRUE,
selected_ranges = list(),
selected_points = list(),
query_layout = character(),
datetimes_as_int64 = FALSE,
encryption_key = character(),
query_condition = new("tiledb_query_condition"),
timestamp_start = as.POSIXct(double(), origin = "1970-01-01"),
timestamp_end = as.POSIXct(double(), origin = "1970-01-01"),
return_as = get_return_as_preference(),
query_statistics = FALSE,
strings_as_factors = getOption("stringsAsFactors", FALSE),
keep_open = FALSE,
sil = list(),
dumpbuffers = character(),
buffers = list(),
ctx = tiledb_get_context(),
as.data.frame = FALSE) {
tiledb_array <- function(
uri,
query_type = c("READ", "WRITE"),
is.sparse = NA,
attrs = character(),
extended = TRUE,
selected_ranges = list(),
selected_points = list(),
query_layout = character(),
datetimes_as_int64 = FALSE,
encryption_key = character(),
query_condition = new("tiledb_query_condition"),
timestamp_start = as.POSIXct(double(), origin = "1970-01-01"),
timestamp_end = as.POSIXct(double(), origin = "1970-01-01"),
return_as = get_return_as_preference(),
query_statistics = FALSE,
strings_as_factors = getOption("stringsAsFactors", FALSE),
keep_open = FALSE,
sil = list(),
dumpbuffers = character(),
buffers = list(),
ctx = tiledb_get_context(),
as.data.frame = FALSE) {
stopifnot(
"Argument 'ctx' must be a tiledb_ctx object" = is(ctx, "tiledb_ctx"),
"Argument 'uri' must be a string scalar" = !missing(uri) && is.scalar(uri, "character"),
Expand Down Expand Up @@ -1829,9 +1830,10 @@ setReplaceMethod("datetimes_as_int64",
#' @param ctx An option TileDB Context object
#' @return NULL is returned invisibly
#' @export
array_consolidate <- function(uri, cfg = NULL,
start_time, end_time,
ctx = tiledb_get_context()) {
array_consolidate <- function(
uri, cfg = NULL,
start_time, end_time,
ctx = tiledb_get_context()) {
stopifnot(`Argument 'uri' must be character` = is.character(uri))
if (is.null(cfg)) {
cfg <- config(ctx)
Expand Down Expand Up @@ -1870,9 +1872,10 @@ array_consolidate <- function(uri, cfg = NULL,
#' @param ctx An option TileDB Context object
#' @return NULL is returned invisibly
#' @export
array_vacuum <- function(uri, cfg = NULL,
start_time, end_time,
ctx = tiledb_get_context()) {
array_vacuum <- function(
uri, cfg = NULL,
start_time, end_time,
ctx = tiledb_get_context()) {
stopifnot(`Argument 'uri' must be character` = is.character(uri))
if (is.null(cfg)) {
cfg <- config(ctx)
Expand Down
15 changes: 8 additions & 7 deletions R/Utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,14 @@ r_to_tiledb_type <- function(x) {
}

## conversion helper from (and to) legacy validity map for nullable strings
.legacy_validity <- function(inuri,
outdir = NULL,
fromlegacy = TRUE,
tolegacy = FALSE,
usetmp = FALSE,
verbose = FALSE,
debug = FALSE) {
.legacy_validity <- function(
inuri,
outdir = NULL,
fromlegacy = TRUE,
tolegacy = FALSE,
usetmp = FALSE,
verbose = FALSE,
debug = FALSE) {
stopifnot("'inuri' must be an existing directory" = dir.exists(inuri))

if (verbose) {
Expand Down
5 changes: 3 additions & 2 deletions R/VFS.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ tiledb_set_vfs <- function(vfs) {
#' @param ctx (optional) A TileDB Ctx object
#' @return A TileDB VFS Filehandle object (as an external pointer)
#' @export
tiledb_vfs_open <- function(binfile, mode = c("READ", "WRITE", "APPEND"),
vfs = tiledb_get_vfs(), ctx = tiledb_get_context()) {
tiledb_vfs_open <- function(
binfile, mode = c("READ", "WRITE", "APPEND"),
vfs = tiledb_get_vfs(), ctx = tiledb_get_context()) {
mode <- match.arg(mode)
stopifnot(
`Argument 'vfs' must be a tiledb_vfs object` = is(vfs, "tiledb_vfs"),
Expand Down

0 comments on commit 498e8e9

Please sign in to comment.