-
Notifications
You must be signed in to change notification settings - Fork 23
Add Profile API to TileDB-R #856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
78c84cf
(WIP) Add internal RCpp functions for Profile
jp-dark 0314ee3
Fix optional string conversion and export typo
jp-dark 06f80e1
Add Profile R code
jp-dark 3e073e1
Clean-up return types
jp-dark b3300d9
Update Profile Roxygen2 and fix typo
jp-dark c6dedaf
Fix typo in Rcpp::export
jp-dark c4a7a33
Add basic profile test
jp-dark cb44dc6
Add test for using profile in config
jp-dark 8b1a960
Fix test
jp-dark 7e3c0e2
Fix test for windows paths
jp-dark 1847134
Update pkgdown index
jp-dark 5a8d1c0
Properly normalize paths in tests
jp-dark c78b128
Normalize expected dir in test as well
jp-dark 8cba032
Fix update to pkgdown yaml
jp-dark e1f0142
Update roxygen docs
jp-dark 3545278
Fix pkgdown.yml
jp-dark a520af9
Add Profile S4 methods to pkgdown index
jp-dark 5103065
Update version and news
jp-dark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # | ||
| # Copyright (c) TileDB Inc. under the MIT License | ||
| # | ||
|
|
||
| #' An S4 class for a TileDB Profile object | ||
| #' | ||
| #' @slot ptr An external pointer to the underlying implementation | ||
| #' @exportClass tiledb_profile | ||
| setClass("tiledb_profile", | ||
| slots = list(ptr = "externalptr") | ||
| ) | ||
|
|
||
| #' Raw display of a profile object | ||
| #' | ||
| #' This method uses the display method provided by the underlying library. | ||
| #' | ||
| #' @param object A profile object | ||
| #' @export | ||
| setMethod( | ||
| "raw_dump", | ||
| signature(object = "tiledb_profile"), | ||
| definition = function(object) libtiledb_profile_dump(object@ptr) | ||
| ) | ||
|
|
||
| #' Create a 'tiledb_profile' object | ||
| #' | ||
| #' @param name (optional) Name for the profile | ||
| #' @param dir (optional) Directory to create the profile in | ||
| #' @return A new 'tiledb_profile' object | ||
| #' @export | ||
| tiledb_profile <- function(name = NULL, dir = NULL) { | ||
| stopifnot(`The 'name' for the profile must be null or a character type` = is.null(name) || is.character(name)) | ||
| stopifnot(`The 'dir' for the profile must be null or a character type` = is.null(name) || is.character(name)) | ||
| ptr <- libtiledb_profile_new(name, dir) | ||
| profile <- new("tiledb_profile", ptr = ptr) | ||
| return(profile) | ||
| } | ||
|
|
||
| #' Load a saved 'tiledb_profile' object | ||
| #' | ||
| #' @param name (optional) Name of the profile to load | ||
| #' @param dir (optional) Directory where the profile to load is saved | ||
| #' @return The loaded 'tiledb_profile' object | ||
| #' @export | ||
| tiledb_profile_load <- function(name = NULL, dir = NULL) { | ||
| stopifnot(`The 'name' for the profile must be null or a character type` = is.null(name) || is.character(name)) | ||
| stopifnot(`The 'dir' for the profile must be null or a character type` = is.null(name) || is.character(name)) | ||
| ptr <- libtiledb_profile_load(name, dir) | ||
| profile <- new("tiledb_profile", ptr = ptr) | ||
| return(profile) | ||
| } | ||
|
|
||
| #' Remove a saved 'tiledb_profile' | ||
| #' | ||
| #' @param name (optional) Name of the profile to remove | ||
| #' @param dir (optional) Directory where the profile to remove is saved | ||
| #' @export | ||
| tiledb_profile_remove <- function(name = NULL, dir = NULL) { | ||
| stopifnot(`The 'name' for the profile must be null or a character type` = is.null(name) || is.character(name)) | ||
| stopifnot(`The 'dir' for the profile must be null or a character type` = is.null(name) || is.character(name)) | ||
| libtiledb_profile_remove(name, dir) | ||
| return(invisible(NULL)) | ||
| } | ||
|
|
||
| #' Get the name of a 'tiledb_profile' object | ||
| #' | ||
| #' @param profile A TileDB profile object | ||
| #' @return The name of the 'tiledb_profile' object | ||
| #' @export | ||
| tiledb_profile_name <- function(profile) { | ||
| stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) | ||
| name <- libtiledb_profile_name(profile@ptr) | ||
| return(name) | ||
| } | ||
|
|
||
| #' Get the directory of a 'tiledb_profile' object | ||
| #' | ||
| #' @param profile A TileDB profile object | ||
| #' @return The directory of the 'tiledb_profile' object | ||
| #' @export | ||
| tiledb_profile_dir <- function(profile) { | ||
| stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) | ||
| dir <- libtiledb_profile_dir(profile@ptr) | ||
| return(dir) | ||
| } | ||
|
|
||
| #' Set a parameter on the 'tiledb_profile' object | ||
| #' | ||
| #' @param profile A TileDB profile object | ||
| #' @param param The key for the new parameter | ||
| #' @param value The value for the new parameter | ||
| #' @export | ||
| tiledb_profile_set_param <- function(profile, param, value) { | ||
| stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) | ||
| stopifnot(`The 'param' arugment must have character type` = is.character(param)) | ||
| stopifnot(`The 'value' arugment must have character type` = is.character(value)) | ||
| libtiledb_profile_set_param(profile@ptr, param, value) | ||
| return(invisible(NULL)) | ||
| } | ||
|
|
||
| #' Get the value of a parameter set on the 'tiledb_profile' object | ||
| #' | ||
| #' @param profile A TileDB profile object | ||
| #' @param param The key for the parameter to fetch | ||
| #' @return The value of the requested parameter or NULL if no such parameter exists | ||
| #' @export | ||
| tiledb_profile_get_param <- function(profile, param) { | ||
| stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) | ||
| stopifnot(`The 'param' arugment must have character type` = is.character(param)) | ||
| value <- libtiledb_profile_get_param(profile@ptr, param) | ||
| return(value) | ||
| } | ||
|
|
||
| #' Save the 'tiledb_profile' object | ||
| #' | ||
| #' This will save the 'tiledb_profile' with the name and directory set at creation. | ||
| #' | ||
| #' @param profile The 'tiledb_profile' object to save | ||
| #' @export | ||
| tiledb_profile_save <- function(profile) { | ||
| stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) | ||
| libtiledb_profile_save(profile@ptr) | ||
| return(invisible(NULL)) | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| library(tinytest) | ||
| library(tiledb) | ||
|
|
||
| # Use base directory to prevent over-writing user profiles. | ||
| name <- "test_profile" | ||
| dir <- file.path(tempdir(), "tiledb_config_profile/") | ||
|
|
||
| # Create profile | ||
| profile <- tiledb_profile(name, dir) | ||
|
|
||
| # Set some parameters | ||
| token <- "12345" | ||
| server_address <- "https://profile_address.com" | ||
| tiledb_profile_set_param(profile, "rest.token", token) | ||
| tiledb_profile_set_param(profile, "rest.server_address", server_address) | ||
|
|
||
| # Save the profile | ||
| tiledb_profile_save(profile) | ||
|
|
||
|
|
||
| # Create a config and set the profile directory | ||
| config <- tiledb_config(c(profile_name = name, profile_dir = dir)) | ||
| config_profile_name <- config["profile_name"] | ||
| config_profile_dir <- config["profile_dir"] | ||
| config_rest_token <- config["rest.token"] | ||
| config_rest_server_address <- config["rest.server_address"] | ||
|
|
||
| # Test that the config parameters are set correctly | ||
| expect_equal(config["profile_name"], c(profile_name = name)) | ||
| expect_equal(config["profile_dir"], c(profile_dir = dir)) | ||
| expect_equal(config["rest.token"], c(rest.token = token)) | ||
| expect_equal(config["rest.server_address"], c(rest.server_address = server_address)) | ||
|
|
||
|
|
||
| # Remove the profile | ||
| tiledb_profile_remove(name, dir) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| library(tinytest) | ||
| library(tiledb) | ||
|
|
||
| # Use base directory to prevent over-writing user profiles. | ||
| base_dir <- tempdir() | ||
| dir1 <- file.path(base_dir, "tiledb_profile") | ||
|
|
||
|
|
||
| # 1. Test creating profiles. | ||
| profile1 <- tiledb_profile() | ||
| profile2 <- tiledb_profile("profile2") | ||
| profile3 <- tiledb_profile(dir=dir1) | ||
| profile4 <- tiledb_profile("profile4", dir1) | ||
|
|
||
| expect_equal(tiledb_profile_name(profile1), "default") | ||
| expect_equal(tiledb_profile_name(profile2), "profile2") | ||
| expect_equal(tiledb_profile_name(profile3), "default") | ||
| expect_equal(tiledb_profile_name(profile4), "profile4") | ||
|
|
||
| # Skipping checks for default directory since it is platform dependent. | ||
| # Normalize paths on Windows to UNIX-style | ||
| expected_dir <- normalizePath( | ||
| path = dir1, | ||
| winslash = "/", | ||
| mustWork = FALSE | ||
| ) | ||
| actual_dir_profile3 <- normalizePath( | ||
| path = tiledb_profile_dir(profile3), | ||
| winslash = "/", | ||
| mustWork = FALSE | ||
| ) | ||
| expect_identical( | ||
| # trim trailing slashes | ||
| current = sub(pattern = "/+$", replacement = "", x = actual_dir_profile3), | ||
| target = expected_dir | ||
| ) | ||
| actual_dir_profile4 <- normalizePath( | ||
| path = tiledb_profile_dir(profile4), | ||
| winslash = "/", | ||
| mustWork = FALSE | ||
| ) | ||
| expect_identical( | ||
| current = sub(pattern = "/+$", replacement = "", x = actual_dir_profile4), | ||
| target = expected_dir | ||
| ) | ||
|
|
||
|
|
||
| # 2. Test setting/getting profile parameters. | ||
| key1 <- "username" | ||
| key2 <- "server_address" | ||
| key3 <- "rest.token" | ||
| expected_value1 <- "my_username" | ||
| expected_value2 <- "https://my.address" | ||
| expected_value3 <- "123456" | ||
|
|
||
| tiledb_profile_set_param(profile4, key1, expected_value1) | ||
| tiledb_profile_set_param(profile4, key2, expected_value2) | ||
| tiledb_profile_set_param(profile4, key3, expected_value3) | ||
|
|
||
| actual_value1 <- tiledb_profile_get_param(profile4, key1) | ||
| actual_value2 <- tiledb_profile_get_param(profile4, key2) | ||
| actual_value3 <- tiledb_profile_get_param(profile4, key3) | ||
| actual_non_value <- tiledb_profile_get_param(profile4, "not_a_parameter") | ||
|
|
||
| expect_equal(actual_value1, expected_value1) | ||
| expect_equal(actual_value2, expected_value2) | ||
| expect_equal(actual_value3, expected_value3) | ||
| expect_true(is.null(actual_non_value)) | ||
|
|
||
| # 3. Test save, load, and remove. | ||
| # IMPORTANT: Do not save a profile to a location that might over-write an actual profile. | ||
| tiledb_profile_save(profile3) | ||
| tiledb_profile_save(profile4) | ||
|
|
||
| # -- Check can load profile3 | ||
| profile_loaded <- tiledb_profile_load(dir=dir1) | ||
|
|
||
| # -- Remove profile2. Check can no longer load. | ||
| tiledb_profile_remove(dir=dir1) | ||
| expect_error(tiledb_profile_load(dir=dir1)) | ||
|
|
||
| # -- Check loaded profile4 | ||
| profile_loaded <- tiledb_profile_load("profile4", dir1) | ||
| expect_equal(tiledb_profile_name(profile_loaded), "profile4") | ||
| expect_equal(tiledb_profile_name(profile_loaded), "profile4") | ||
| loaded_value1 <- tiledb_profile_get_param(profile_loaded, key1) | ||
| loaded_value2 <- tiledb_profile_get_param(profile_loaded, key2) | ||
| loaded_value3 <- tiledb_profile_get_param(profile_loaded, key3) | ||
| loaded_non_value <- tiledb_profile_get_param(profile_loaded, "not_a_parameter") | ||
| expect_equal(loaded_value1, expected_value1) | ||
| expect_equal(loaded_value2, expected_value2) | ||
| expect_equal(loaded_value3, expected_value3) | ||
| expect_true(is.null(loaded_non_value)) | ||
|
|
||
| # -- Remove profile4 | ||
| tiledb_profile_remove("profile4", dir1) | ||
|
|
||
| # -- Check cannot load profile2 or profile4. | ||
| expect_error(tiledb_profile_load(dir=dir1)) | ||
| expect_error(tiledb_profile_load("profile4", dir1)) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.