Repository navigation
Fix dense [<- writes and support [i, j, k] and selected_ranges() - #896
Merged
Merged
Conversation
Dense `[<-` silently wrote nothing for one-column right-hand sides, rejected three-column ones as dimension/attribute columns, ignored `selected_ranges()`, and built an INT32-only 2-d subarray from `range(i)` and `range(j)`. Writes now build a typed subarray for any number of dimensions from `[i, j, k]` or `selected_ranges()`, matching `[`. Closes #877 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jdblischak
approved these changes
Oct 22, 2026
jdblischak
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @mojaveazure!
I recommend bumping the version in DESCRIPTION to 0.34.0.1
I confirmed that this PR fixes the errors from the example provided in #877 (comment)
git log -n 1 --oneline
## 43cabd22 (HEAD -> fix/dense-assign-nd) Fix dense `[<-` writes and support `[i, j, k]` and `selected_ranges()`
docker run --rm -it -v $(pwd):/TileDB-R rocker/r2u:latest bash
cd TileDB-R/
apt update -qq && apt install --yes --no-install-recommends cmake curl git
Rscript -e 'remotes::install_deps(".", dependencies=TRUE)'
R CMD build --no-build-vignettes --no-manual .
R CMD INSTALL --use-C17 tiledb_0.34.0.tar.gzlibrary("tiledb")
## TileDB R 0.34.0 with TileDB Embedded 2.30.0 on Ubuntu 24.04.4 LTS.
## See https://tiledb.com for more information about TileDB.
tmp <- tempfile()
dom <- tiledb_domain(dims = list(
tiledb_dim("d1", c(1L, 4L), 4L, type = "INT32"),
tiledb_dim("d2", c(1L, 3L), 3L, type = "INT32")
))
schema <- tiledb_array_schema(
dom,
attrs = list(tiledb_attr("x", type = "FLOAT64")),
sparse = FALSE
)
tiledb_array_create(tmp, schema)
# ncol=1: no more silent failure
arr <- tiledb_array(tmp, query_type = "WRITE")
selected_ranges(arr) <- list(cbind(1, 4), cbind(1, 1))
arr[] <- matrix(runif(4), 4, 1)
tiledb_array_close(arr)
arr <- tiledb_array(tmp, query_type = "READ")
arr[1:4, 1:3]$x
## [1] 0.9549284 0.1356648 0.5171040 0.3093992 NaN NaN NaN
## [8] NaN NaN NaN NaN NaN
tiledb_array_close(arr)
# ncol=3: no more error
arr2 <- tiledb_array(tmp, query_type = "WRITE")
arr2[1:4, 1:3] <- matrix(runif(12), 4, 3)
arr2[1:4, 1:3]$x
## [1] 0.35634239 0.13263939 0.45245257 0.03139209 0.38876229 0.27229030
## [7] 0.39942395 0.25701818 0.37835856 0.88043968 0.93553177 0.50401161
tiledb_array_close(arr2)
sessionInfo()
## R version 4.6.1 (2026-06-24)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.4 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.12.0
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0 LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices datasets utils methods base
##
## other attached packages:
## [1] RcppSpdlog_0.0.29 tiledb_0.34.0
##
## loaded via a namespace (and not attached):
## [1] zoo_1.9-1 bit_4.6.0 compiler_4.6.1
## [4] tools_4.6.1 RcppCCTZ_0.2.14 spdl_0.0.5
## [7] Rcpp_1.1.2 bspm_0.5.8 nanoarrow_0.9.0
## [10] bit64_4.8.6 nanotime_0.3.15 grid_4.6.1
## [13] data.table_1.18.6.1 lattice_0.23-1
Contributor
|
Perhaps, the documentation for Now that we got this fixed, the helper library(tiledb)
uri <- tempfile()
df1 <- data.frame(index = as.Date(0:1),
a = c(100, 120),
b = c(80, 120))
tiledb::fromDataFrame(df1,
uri,
col_index = 1,
tile_domain = c(0, 10),
sparse = FALSE,
mode = "schema_only")
arr <- tiledb::tiledb_array(uri, return_as = "data.frame")
# nope because we supplied dims
arr[0:1, ] <- df1
#> Error:
#> ! [TileDB::Query] Error: Dense write queries cannot set dimension buffers
# drop dim: index
arr[0:1, ] <- df1[, -1] # NOTE before this PR -> Error: WriterBase: Buffer sizes check failed; Invalid number of cells given for attribute 'b' (2 != 11)
arr[]
#> index a b
#> 1 1970-01-01 100 80
#> 2 1970-01-02 120 120
# Using tiledb::fromDataFrame "ingest" - fails
uri <- tempfile()
tiledb::fromDataFrame(df1,
uri,
col_index = 1,
tile_domain = c(0, 10),
sparse = FALSE,
mode = "ingest")
#> Error:
#> ! [TileDB::Query] Error: Unordered writes are only possible for sparse arrays |
XanthosXanthopoulos
approved these changes
Oct 24, 2026
[ci skip]
This was referenced Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the dense
[<-write bugs reported in #877, and makes dense writes work for 3D+ arrays.Bugs fixed
[i, j]selected_ranges()ncol > 1, but its outerifstill matched, so the list case was skipped as well. The value kept the nameV1, the name check failed, and theifhad noelse, so the method returned without writing. A name mismatch is now an error.as.integer(c(range(i), range(j))), set only when bothiandjwere given and there was a single attribute. It was 2D and INT32 only, ignoredselected_ranges(), and widened non-contiguous indices. Dense writes with multiple attributes never set a subarray.New behavior
arr[i, j, k] <- valueon dense arrays, capturingkthe same way[does (nd_index_from_syscall()). A 4th index is an error, not a message as on the read side, because ignoring it would write to the wrong cells. Sparse writes still useiandjonly.selected_ranges(), named or unnamed, for any number of dimensions. Dimensions with no selection span their full domain.libtiledb_subarray_add_range_with_type()), so INT64 and datetime dimensions work.nd_index_from_syscall()no longer evaluatesvaluea second time.Behavior changes (in NEWS and
?"[<-,tiledb_array-method")These are now errors:
selected_points()on a write;Also:
selected_ranges()left on an array object from an earlier read now apply to writes through it.Known limitation
A dimension with no index or selected range spans its full domain, not its current domain. This only matters for dense arrays that have a current domain set.
Testing
New
inst/tinytest/test_densewrite.R(32 tests):[i, j]andselected_ranges();[i, j, k]and[i, , k], and an array value;selected_ranges()on a 4D array;It's a separate file because
test_tiledbarray.Rcallsexit_file()partway through on macOS and r-universe.Full suite: 1790 tests, 1 failure (
test_config_profile.R,rest.token). The same failure occurs onmain(1758 tests, 1 failure). This was run against the R changes loaded into an installed 0.34.0 build, not a fresh compile; CI will cover that.Closes #877
🤖 Generated with Claude Code