Skip to content

Commit 73a4a1d

Browse files
jp-darkaaronwolen
andauthored
[r] Add and use new SOMAContext object (#4355) (#4358)
* Remove unused private tiledb_ctx member * Remove tests for functions that do not act standalone * Rename createSOMAContext and move to soma_context.cpp * Create and use new SOMAContext R6 class * Add methods to SOMAContext * Update block_size to use new context * More clean-up * Update documentation * Testing and fixes - Fix setting default parameter in contexts - Add tests for SOMAContext using both new and deprecated API * Add soma_context to more places and update tests * Update news * Update docs * Deprecate SOMATileDBContext and check in tests * Update apis/r/R/SOMAObject.R * Apply suggestions from code review * Update apis/r/R/Factory.R * Update apis/r/R/Factory.R --------- (cherry picked from commit e7629a2) Co-authored-by: Aaron Wolen <[email protected]>
1 parent 9aa6609 commit 73a4a1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+964
-414
lines changed

apis/r/NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export(SOMACollection)
5858
export(SOMACollectionBase)
5959
export(SOMACollectionCreate)
6060
export(SOMACollectionOpen)
61+
export(SOMAContext)
6162
export(SOMAContextBase)
6263
export(SOMADataFrame)
6364
export(SOMADataFrameCreate)

apis/r/NEWS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# tiledbsoma 2.3.0
2+
3+
## Deprecated
4+
5+
- The function `soma_context` is deprecated. Use class `SOMAContext` instead. ([#4355](https://github.com/single-cell-data/TileDB-SOMA/pull/4355))
6+
- The parameter `tiledbsoma_ctx` is deprecated in all functions/methods that use it. Use the parameter `soma_context` instead. ([#4355](https://github.com/single-cell-data/TileDB-SOMA/pull/4355))
7+
- `SOMATileDBContext` is deprecated. Use class `SOMAContext` instead. ([#4355](https://github.com/single-cell-data/TileDB-SOMA/pull/4355))
8+
9+
## Fixed
10+
11+
- The SOMA Context is only cached as an environment variable when the function `soma_context` is called directly. ([#4355](https://github.com/single-cell-data/TileDB-SOMA/pull/4355))
12+
- `SOMATileDBContext` no longer replaces `sm.mem.reader.sparse_global_order.ratio_array_data` when set in the input config. ([#4355](https://github.com/single-cell-data/TileDB-SOMA/pull/4355))
13+
114
# tiledbsoma 2.2.0
215

316
## Changed

apis/r/R/Factory.R

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
#' if it already exists, simply open it for writing.
2929
#' }
3030
#' @param platform_config Optional platform configuration.
31-
#' @param tiledbsoma_ctx Optional SOMATileDBContext.
31+
#' @param tiledbsoma_ctx Optional (DEPRECATED) SOMATileDBContext.
3232
#' @param tiledb_timestamp Optional Datetime (POSIXct) for TileDB timestamp.
33-
#' @param soma_context A SOMA context as created by
34-
#' \code{\link{soma_context}()}.
33+
#' @param soma_context Optional TileDB SOMA context.
3534
#'
3635
#' @return A new \link[tiledbsoma:SOMADataFrame]{SOMA data frame} stored at
3736
#' \code{uri} opened for writing.
@@ -68,10 +67,12 @@ SOMADataFrameCreate <- function(
6867
soma_context = NULL
6968
) {
7069
ingest_mode <- match.arg(ingest_mode)
70+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMADataFrameCreate(tiledbsoma_ctx)")
7171
sdf <- SOMADataFrame$new(
7272
uri,
7373
platform_config = platform_config,
7474
tiledbsoma_ctx = tiledbsoma_ctx,
75+
soma_context = soma_context,
7576
tiledb_timestamp = tiledb_timestamp
7677
)
7778
ingest_mode <- switch(
@@ -123,10 +124,12 @@ SOMADataFrameOpen <- function(
123124
uri,
124125
tiledb_timestamp %||% "now"
125126
))
127+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMADataFrameOpen(tiledbsoma_ctx)")
126128
sdf <- SOMADataFrame$new(
127129
uri,
128130
platform_config = platform_config,
129131
tiledbsoma_ctx = tiledbsoma_ctx,
132+
soma_context = soma_context,
130133
tiledb_timestamp = tiledb_timestamp
131134
)
132135
sdf$open(mode)
@@ -172,13 +175,16 @@ SOMASparseNDArrayCreate <- function(
172175
ingest_mode = c("write", "resume"),
173176
platform_config = NULL,
174177
tiledbsoma_ctx = NULL,
175-
tiledb_timestamp = NULL
178+
tiledb_timestamp = NULL,
179+
soma_context = NULL
176180
) {
177181
ingest_mode <- match.arg(ingest_mode)
182+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMASparseNDArrayCreate(tiledbsoma_ctx)")
178183
snda <- SOMASparseNDArray$new(
179184
uri,
180185
platform_config = platform_config,
181186
tiledbsoma_ctx = tiledbsoma_ctx,
187+
soma_context = soma_context,
182188
tiledb_timestamp = tiledb_timestamp
183189
)
184190
ingest_mode <- switch(
@@ -214,13 +220,16 @@ SOMASparseNDArrayOpen <- function(
214220
mode = "READ",
215221
platform_config = NULL,
216222
tiledbsoma_ctx = NULL,
217-
tiledb_timestamp = NULL
223+
tiledb_timestamp = NULL,
224+
soma_context = NULL
218225
) {
226+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMASparseNDArrayOpen(tiledbsoma_ctx)")
219227
snda <- SOMASparseNDArray$new(
220228
uri,
221229
platform_config = platform_config,
222230
tiledbsoma_ctx = tiledbsoma_ctx,
223-
tiledb_timestamp = tiledb_timestamp
231+
tiledb_timestamp = tiledb_timestamp,
232+
soma_context = soma_context
224233
)
225234
snda$open(mode)
226235
return(snda)
@@ -260,17 +269,20 @@ SOMADenseNDArrayCreate <- function(
260269
shape,
261270
platform_config = NULL,
262271
tiledbsoma_ctx = NULL,
263-
tiledb_timestamp = NULL
272+
tiledb_timestamp = NULL,
273+
soma_context = NULL
264274
) {
265275
soma_debug(sprintf(
266276
"[SOMADenseNDArrayCreate] tstamp (%s)",
267277
tiledb_timestamp %||% "now"
268278
))
279+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMADenseNDArrayCreate(tiledbsoma_ctx)")
269280
dnda <- SOMADenseNDArray$new(
270281
uri,
271282
platform_config = platform_config,
272283
tiledbsoma_ctx = tiledbsoma_ctx,
273-
tiledb_timestamp = tiledb_timestamp
284+
tiledb_timestamp = tiledb_timestamp,
285+
soma_context = soma_context
274286
)
275287
dnda$create(type, shape, platform_config = platform_config)
276288
return(dnda)
@@ -296,13 +308,16 @@ SOMADenseNDArrayOpen <- function(
296308
mode = "READ",
297309
platform_config = NULL,
298310
tiledbsoma_ctx = NULL,
299-
tiledb_timestamp = NULL
311+
tiledb_timestamp = NULL,
312+
soma_context = NULL
300313
) {
314+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMADenseNDArrayOpen(tiledbsoma_ctx)")
301315
dnda <- SOMADenseNDArray$new(
302316
uri,
303317
platform_config = platform_config,
304318
tiledbsoma_ctx = tiledbsoma_ctx,
305-
tiledb_timestamp = tiledb_timestamp
319+
tiledb_timestamp = tiledb_timestamp,
320+
soma_context = soma_context
306321
)
307322
dnda$open(mode)
308323
return(dnda)
@@ -340,14 +355,17 @@ SOMACollectionCreate <- function(
340355
ingest_mode = c("write", "resume"),
341356
platform_config = NULL,
342357
tiledbsoma_ctx = NULL,
343-
tiledb_timestamp = NULL
358+
tiledb_timestamp = NULL,
359+
soma_context = NULL
344360
) {
345361
ingest_mode <- match.arg(ingest_mode)
362+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMACollectionCreate(tiledbsoma_ctx)")
346363
coll <- SOMACollection$new(
347364
uri,
348365
platform_config = platform_config,
349366
tiledbsoma_ctx = tiledbsoma_ctx,
350-
tiledb_timestamp = tiledb_timestamp
367+
tiledb_timestamp = tiledb_timestamp,
368+
soma_context = soma_context
351369
)
352370
ingest_mode <- switch(
353371
EXPR = ingest_mode,
@@ -384,13 +402,16 @@ SOMACollectionOpen <- function(
384402
mode = "READ",
385403
platform_config = NULL,
386404
tiledbsoma_ctx = NULL,
387-
tiledb_timestamp = NULL
405+
tiledb_timestamp = NULL,
406+
soma_context = NULL
388407
) {
408+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMACollectionOpen(tiledbsoma_ctx)")
389409
coll <- SOMACollection$new(
390410
uri,
391411
platform_config = platform_config,
392412
tiledbsoma_ctx = tiledbsoma_ctx,
393-
tiledb_timestamp = tiledb_timestamp
413+
tiledb_timestamp = tiledb_timestamp,
414+
soma_context = soma_context
394415
)
395416
coll$open(mode)
396417
return(coll)
@@ -440,14 +461,17 @@ SOMAMeasurementCreate <- function(
440461
ingest_mode = c("write", "resume"),
441462
platform_config = NULL,
442463
tiledbsoma_ctx = NULL,
443-
tiledb_timestamp = NULL
464+
tiledb_timestamp = NULL,
465+
soma_context = NULL
444466
) {
445467
ingest_mode <- match.arg(ingest_mode)
468+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMAMeasurementCreate(tiledbsoma_ctx)")
446469
meas <- SOMAMeasurement$new(
447470
uri,
448471
platform_config = platform_config,
449472
tiledbsoma_ctx = tiledbsoma_ctx,
450-
tiledb_timestamp = tiledb_timestamp
473+
tiledb_timestamp = tiledb_timestamp,
474+
soma_context = soma_context
451475
)
452476
ingest_mode <- switch(
453477
EXPR = ingest_mode,
@@ -482,13 +506,16 @@ SOMAMeasurementOpen <- function(
482506
mode = "READ",
483507
platform_config = NULL,
484508
tiledbsoma_ctx = NULL,
485-
tiledb_timestamp = NULL
509+
tiledb_timestamp = NULL,
510+
soma_context = NULL
486511
) {
512+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMAMeasurementOpen(tiledbsoma_ctx)")
487513
meas <- SOMAMeasurement$new(
488514
uri,
489515
platform_config = platform_config,
490516
tiledbsoma_ctx = tiledbsoma_ctx,
491-
tiledb_timestamp = tiledb_timestamp
517+
tiledb_timestamp = tiledb_timestamp,
518+
soma_context = soma_context
492519
)
493520
meas$open(mode)
494521
return(meas)
@@ -538,14 +565,17 @@ SOMAExperimentCreate <- function(
538565
ingest_mode = c("write", "resume"),
539566
platform_config = NULL,
540567
tiledbsoma_ctx = NULL,
541-
tiledb_timestamp = NULL
568+
tiledb_timestamp = NULL,
569+
soma_context = NULL
542570
) {
543571
ingest_mode <- match.arg(ingest_mode)
572+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMAExperimentCreate(tiledbsoma_ctx)")
544573
exp <- SOMAExperiment$new(
545574
uri,
546575
platform_config = platform_config,
547576
tiledbsoma_ctx = tiledbsoma_ctx,
548-
tiledb_timestamp = tiledb_timestamp
577+
tiledb_timestamp = tiledb_timestamp,
578+
soma_context = soma_context
549579
)
550580
ingest_mode <- switch(
551581
EXPR = ingest_mode,
@@ -579,13 +609,16 @@ SOMAExperimentOpen <- function(
579609
mode = "READ",
580610
platform_config = NULL,
581611
tiledbsoma_ctx = NULL,
582-
tiledb_timestamp = NULL
612+
tiledb_timestamp = NULL,
613+
soma_context = NULL
583614
) {
615+
soma_context <- get_soma_context(soma_context, tiledbsoma_ctx, what="SOMAExperimentOpen(tiledbsoma_ctx)")
584616
exp <- SOMAExperiment$new(
585617
uri,
586618
platform_config = platform_config,
587619
tiledbsoma_ctx = tiledbsoma_ctx,
588-
tiledb_timestamp = tiledb_timestamp
620+
tiledb_timestamp = tiledb_timestamp,
621+
soma_context = soma_context
589622
)
590623
exp$open(mode)
591624
return(exp)

apis/r/R/RcppExports.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
22
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
33

4-
createSOMAContext <- function(config = NULL) {
5-
.Call(`_tiledbsoma_createSOMAContext`, config)
6-
}
7-
84
createSchemaFromArrow <- function(uri, nasp, nadimap, nadimsp, sparse, datatype, pclst, ctxxp, tsvec = NULL) {
95
invisible(.Call(`_tiledbsoma_createSchemaFromArrow`, uri, nasp, nadimap, nadimsp, sparse, datatype, pclst, ctxxp, tsvec))
106
}
@@ -386,3 +382,15 @@ get_tiledb_object_type <- function(uri, ctxxp) {
386382
.Call(`_tiledbsoma_get_tiledb_object_type`, uri, ctxxp)
387383
}
388384

385+
create_soma_context <- function(config = NULL) {
386+
.Call(`_tiledbsoma_create_soma_context`, config)
387+
}
388+
389+
get_config_from_soma_context <- function(soma_context) {
390+
.Call(`_tiledbsoma_get_config_from_soma_context`, soma_context)
391+
}
392+
393+
get_data_protocol_from_soma_context <- function(soma_context, uri) {
394+
.Call(`_tiledbsoma_get_data_protocol_from_soma_context`, soma_context, uri)
395+
}
396+

apis/r/R/SOMAArrayBase.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,21 @@ SOMAArrayBase <- R6::R6Class(
9595
#' @return \code{TRUE} if the underlying TileDB array allows duplicates;
9696
#' otherwise \code{FALSE}.
9797
#'
98-
allows_duplicates = \() c_allows_dups(self$uri, private$.soma_context),
98+
allows_duplicates = \() c_allows_dups(self$uri, private$.soma_context$handle),
9999

100100
#' @description Is an array sparse?
101101
#'
102102
#' @return \code{TRUE} if the underlying TileDB array is sparse;
103103
#' otherwise \code{FALSE}.
104104
#'
105-
is_sparse = \() c_is_sparse(self$uri, private$.soma_context),
105+
is_sparse = \() c_is_sparse(self$uri, private$.soma_context$handle),
106106

107107
#' @description Retrieve the array schema as an Arrow schema
108108
#' (lifecycle: maturing).
109109
#'
110110
#' @return An Arrow \code{\link[arrow:Schema]{Schema}} object.
111111
#'
112-
schema = \() arrow::as_schema(c_schema(self$uri, private$.soma_context)),
112+
schema = \() arrow::as_schema(c_schema(self$uri, private$.soma_context$handle)),
113113

114114
#' @description Retrieve the array attributes.
115115
#'
@@ -133,13 +133,13 @@ SOMAArrayBase <- R6::R6Class(
133133
#' }
134134
#' }
135135
#'
136-
attributes = \() c_attributes(self$uri, private$.soma_context),
136+
attributes = \() c_attributes(self$uri, private$.soma_context$handle),
137137

138138
#' @description Retrieve attribute names (lifecycle: maturing).
139139
#'
140140
#' @return A character vector with the array's attribute names.
141141
#'
142-
attrnames = \() c_attrnames(self$uri, private$.soma_context),
142+
attrnames = \() c_attrnames(self$uri, private$.soma_context$handle),
143143

144144
#' @description Retrieve the array dimensions (lifecycle: maturing)
145145
#'
@@ -164,13 +164,13 @@ SOMAArrayBase <- R6::R6Class(
164164
#' }
165165
#' }
166166
#'
167-
dimensions = \() c_domain(self$uri, private$.soma_context),
167+
dimensions = \() c_domain(self$uri, private$.soma_context$handle),
168168

169169
#' @description Retrieve dimension names (lifecycle: maturing).
170170
#'
171171
#' @return A character vector with the array's dimension names.
172172
#'
173-
dimnames = \() c_dimnames(self$uri, private$.soma_context),
173+
dimnames = \() c_dimnames(self$uri, private$.soma_context$handle),
174174

175175
#' @description Retrieve the names of all columns, including dimensions and
176176
#' attributes (lifecycle: maturing).
@@ -195,7 +195,7 @@ SOMAArrayBase <- R6::R6Class(
195195
#' @return A named vector of dimension length and of the same type as
196196
#' the dimension.
197197
#'
198-
shape = \() bit64::as.integer64(shape(self$uri, private$.soma_context)),
198+
shape = \() bit64::as.integer64(shape(self$uri, private$.soma_context$handle)),
199199

200200
#' @description Retrieve the hard limit up to which the array may be resized
201201
#' using the \code{$resize()} method (lifecycle: maturing).
@@ -204,7 +204,7 @@ SOMAArrayBase <- R6::R6Class(
204204
#' the dimension.
205205
#'
206206
maxshape = \() {
207-
bit64::as.integer64(maxshape(self$uri, private$.soma_context))
207+
bit64::as.integer64(maxshape(self$uri, private$.soma_context$handle))
208208
},
209209

210210
#' @description Returns a named list of minimum/maximum pairs, one per index
@@ -222,7 +222,7 @@ SOMAArrayBase <- R6::R6Class(
222222
retval <- as.list(
223223
arrow::as_record_batch(
224224
arrow::as_arrow_table(
225-
non_empty_domain(self$uri, private$.soma_context)
225+
non_empty_domain(self$uri, private$.soma_context$handle)
226226
)
227227
)
228228
)
@@ -240,7 +240,7 @@ SOMAArrayBase <- R6::R6Class(
240240
#'
241241
#' @return A scalar with the number of dimensions.
242242
#'
243-
ndim = \() ndim(self$uri, private$.soma_context),
243+
ndim = \() ndim(self$uri, private$.soma_context$handle),
244244

245245
#' @description Print-friendly representation of the object.
246246
#'

0 commit comments

Comments
 (0)