Skip to content

Commit

Permalink
Safer check for NAs in tiledb_config() (#519)
Browse files Browse the repository at this point in the history
* Safer check for NAs in `tiledb_config()`
Replace `if(is.na())` as R 4.2 errors when conditions > 1L
Instead, removes NAs from `config`
Then, checks the length of `config`; if there is a length, adds it to
the TileDB config

fixes #518

* Update tests for input vectors and NAs

* Update changelog

[ci_skip]
  • Loading branch information
mojaveazure authored Feb 14, 2023
1 parent 49d66f4 commit 6abcd6e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# tiledb 0.18.0.2 (Development)

* This release of the R package builds against [TileDB 2.14.1](https://github.com/TileDB-Inc/TileDB/releases/tag/2.14.1), and has also been tested against earlier releases as well as the development version (#502).
* Safer checking of `NAs` in `tiledb_config()` to support R 4.2 conditional lengths (#518, #519)

## Improvements

Expand Down
3 changes: 2 additions & 1 deletion R/Config.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ tiledb_config.from_ptr <- function(ptr) {
#' @importFrom methods new
#' @export tiledb_config
tiledb_config <- function(config = NA_character_) {
if (!is.na(config)) {
config <- config[!is.na(x = config)]
if (length(x = config)) {
stopifnot(`If given, the 'config' argument must be a name, value character vector` = is.character(config) && !is.null(names(config)))
ptr <- libtiledb_config(config)
} else {
Expand Down
9 changes: 9 additions & 0 deletions inst/tinytest/test_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ expect_error(tiledb_config(1))
expect_error(tiledb_config(c(foo = 1)))
#})

## handle cases with NAs
expect_silent(cfg <- tiledb_config(c(a = "1")))
expect_equal(cfg["a"], c(a = "1"))
expect_silent(cfg <- tiledb_config(c(a = "1", b = "2")))
expect_equal(cfg["b"], c(b = "2"))
expect_equal(head(names(as.vector(cfg)), 2L), c("a", "b"))
expect_silent(cfg <- tiledb_config(c(a = "1", c = NA_character_, b = "2")))
expect_equal(head(names(as.vector(cfg)), 2L), c("a", "b"))

#test_that("tiledb_config indexing works", {
cfg <- tiledb_config()
cfg["foo"] <- "bar"
Expand Down

0 comments on commit 6abcd6e

Please sign in to comment.