Skip to content
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

introduce teal_data class #178

Merged
merged 92 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
e622149
any data possible
gogonzo Aug 14, 2023
9827de3
Merge remote-tracking branch 'origin/main' into refactor
gogonzo Aug 14, 2023
2daf83a
Merge remote-tracking branch 'origin/main' into refactor
gogonzo Aug 15, 2023
bef092f
ddl
gogonzo Aug 15, 2023
3f723f3
Merge bef092fd1955e566716e9d182b647657d1eac1ca into ba573f2544bf8591e…
gogonzo Aug 15, 2023
5e3c0cb
[skip actions] Restyle files
github-actions[bot] Aug 15, 2023
7429b55
adjust to teal
gogonzo Aug 15, 2023
e964b95
fix
gogonzo Aug 15, 2023
1b1ebc6
Merge e964b95be5111216e924621b7793ff046249de99 into ba573f2544bf8591e…
gogonzo Aug 15, 2023
3f37efe
[skip actions] Restyle files
github-actions[bot] Aug 15, 2023
212806c
change arg names
gogonzo Aug 16, 2023
7d9e2b0
Merge branch 'main' into refactor
gogonzo Sep 4, 2023
7edaf2a
cleanup builds
m7pr Sep 7, 2023
b30029b
@anverissimo review
gogonzo Sep 7, 2023
2248740
Merge remote-tracking branch 'origin/main' into refactor
gogonzo Sep 28, 2023
1ca4cb1
ddl alternative (#167)
chlebowa Sep 29, 2023
6504197
ddl WIP
gogonzo Sep 29, 2023
d067b93
POC
gogonzo Sep 29, 2023
56a7b2d
tdata -> teal_data
gogonzo Sep 29, 2023
f3876df
mask_args -> input_mask
gogonzo Oct 3, 2023
c407adf
online_args -> input
gogonzo Oct 3, 2023
5443613
ddl_run - input can be of class "reactivevalues"
gogonzo Oct 3, 2023
48e0f3b
handling datanames information
gogonzo Oct 3, 2023
6b46e4c
ddl from teal.data to teal
gogonzo Oct 3, 2023
2c9da20
teal_data class only
gogonzo Oct 4, 2023
fc853ad
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 4, 2023
b56ee4e
remove to_relational for classes which doesn't need transformation
gogonzo Oct 4, 2023
4ff57d0
specify datanames when more objects in environment
gogonzo Oct 4, 2023
32adc7c
Fix the unit tests for the teal_data refactor (#172)
vedhav Oct 5, 2023
7300049
reload NAMESPACE
gogonzo Oct 5, 2023
4900aef
adding temporary mutate_data for teal_data
gogonzo Oct 5, 2023
f7204f4
fixing preprocessing-data vignette
gogonzo Oct 5, 2023
67f96e4
waiting for parser
gogonzo Oct 5, 2023
801bc72
preparing to use parser
gogonzo Oct 5, 2023
7118d58
teal_data no longer returns TealData when data are available.
gogonzo Oct 5, 2023
c461980
fix
gogonzo Oct 5, 2023
75095ec
wrong package namespace for get_code
gogonzo Oct 5, 2023
36d4544
reverting breaking changes
gogonzo Oct 5, 2023
2fb8a39
fixing R cmd check
gogonzo Oct 5, 2023
0e26f43
new_teal_data(env) new_teal_data(data)
gogonzo Oct 6, 2023
e62f3a7
fixing namespace warning
gogonzo Oct 6, 2023
2680837
following changes in teal.code
gogonzo Oct 9, 2023
4f26d55
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 9, 2023
75f0890
fix
gogonzo Oct 10, 2023
2c0e3f7
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 10, 2023
7cb1986
Merge remote-tracking branch 'origin/main' into teal_data@main
gogonzo Oct 17, 2023
55d0dbc
need higher version of teal.code - code slot is a character
gogonzo Oct 17, 2023
9b3c303
update pkgdown
gogonzo Oct 18, 2023
985d06c
link S4 class
gogonzo Oct 18, 2023
0bb43d8
fix staged.deps
gogonzo Oct 19, 2023
1720d43
fix spelling
gogonzo Oct 19, 2023
b3cea7d
new teal_data examples in the docs
gogonzo Oct 19, 2023
67dea47
- only one constructor for teal_data
gogonzo Oct 20, 2023
d4a8a5d
Merge 67dea470f6fddaea1ef4823cd3ff736efc8f8f80 into c04b7edef44d80fd4…
gogonzo Oct 20, 2023
d869de6
[skip actions] Restyle files
github-actions[bot] Oct 20, 2023
b944347
fix asserts
gogonzo Oct 20, 2023
2485c0b
Merge b94434792cd982244b9c315817a61f7c593ca501 into c04b7edef44d80fd4…
gogonzo Oct 20, 2023
b7d7038
[skip actions] Restyle files
github-actions[bot] Oct 20, 2023
095a9be
fix spelling
gogonzo Oct 20, 2023
1a08953
fix error. Todo: resolve dependency on format_expression
gogonzo Oct 23, 2023
9fb959d
include format_expression to the internals of teal.data -
gogonzo Oct 23, 2023
904998e
Merge 9fb959d5db69ec3278e7918bbad29ef304bf6df8 into c04b7edef44d80fd4…
gogonzo Oct 23, 2023
d926022
[skip actions] Restyle files
github-actions[bot] Oct 23, 2023
8a7dbc4
fix constructor docs of new_teal_data
gogonzo Oct 23, 2023
a3ebc25
Apply suggestions from code review
gogonzo Oct 23, 2023
d8be870
fix tests for teal_data
gogonzo Oct 23, 2023
8348640
Merge d8be8705e8edd0e6ede85909c5fbec4f5822044a into c04b7edef44d80fd4…
gogonzo Oct 23, 2023
8f3b812
[skip actions] Restyle files
github-actions[bot] Oct 23, 2023
bb6e0ff
add test for locked environment
gogonzo Oct 23, 2023
18e1055
linking to GH discussion page
gogonzo Oct 24, 2023
0e727c7
Simplifies data constructor for primary keys in `join_keys` (#179)
averissimo Oct 25, 2023
3f93eae
Merge 0e727c7cb39a8bf89d821de995182b35f9e625c3 into c04b7edef44d80fd4…
gogonzo Oct 25, 2023
cebb61f
[skip actions] Restyle files
github-actions[bot] Oct 25, 2023
4a0aeb9
further constructor simplification simplification
gogonzo Oct 25, 2023
f3de72c
tidyup docs
gogonzo Oct 25, 2023
996d080
fix lintr
gogonzo Oct 25, 2023
4c03c22
- rename keys to join_keys in new_teal_data
gogonzo Oct 25, 2023
5936220
lintr fix
gogonzo Oct 25, 2023
88fc42d
fix tests
gogonzo Oct 25, 2023
2355695
move get_join_keys.default from teal
gogonzo Oct 25, 2023
bfa77c1
add get_join_keys for TealData
gogonzo Oct 25, 2023
9c73c29
add `datanames` function (#181)
chlebowa Oct 27, 2023
a1e092c
to support dynamic list
gogonzo Oct 27, 2023
2fdfeed
Apply suggestions from code review
gogonzo Oct 27, 2023
4dd52bd
@chlebowa review
gogonzo Oct 30, 2023
f10d94a
@chlebowa
gogonzo Oct 30, 2023
ffa1e00
update documentation in teal_data.R
Oct 30, 2023
7771928
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 30, 2023
d7b3bcd
using [fun()] in roxygen2 docs
gogonzo Oct 30, 2023
3bc4e6b
initialize empty teal_data
gogonzo Oct 30, 2023
0dc21e0
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 30, 2023
5ba4f99
empty
gogonzo Oct 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Imports:
shinyjs,
stats,
teal.logger (>= 0.1.1),
teal.code (>= 0.4.1.9003),
pawelru marked this conversation as resolved.
Show resolved Hide resolved
utils,
yaml (>= 1.1.0)
Suggests:
Expand All @@ -57,7 +58,7 @@ Config/Needs/verdepcheck: rstudio/shiny, mllg/checkmate,
yaml=vubiostat/r-yaml, rstudio/bslib, tidyverse/dplyr, yihui/knitr,
tidyverse/magrittr, bioc::MultiAssayExperiment, tidyverse/readr,
rstudio/reticulate, rstudio/rmarkdown, bioc::SummarizedExperiment,
r-lib/testthat, r-lib/withr
insightsengineering/teal.code, r-lib/testthat, r-lib/withr
Config/Needs/website: insightsengineering/nesttemplate
Encoding: UTF-8
Language: en-US
Expand Down
19 changes: 17 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Generated by roxygen2: do not edit by hand

S3method("[",JoinKeys)
S3method("[<-",JoinKeys)
S3method("get_join_keys<-",JoinKeys)
S3method("get_join_keys<-",teal_data)
S3method(as_cdisc,TealDataset)
S3method(as_cdisc,TealDatasetConnector)
S3method(dataset,MultiAssayExperiment)
Expand All @@ -12,6 +16,7 @@ S3method(get_code,default)
S3method(get_dataname,TealDataAbstract)
S3method(get_dataname,TealDataset)
S3method(get_dataname,TealDatasetConnector)
S3method(get_dataname,teal_data)
S3method(get_dataset,TealDataAbstract)
S3method(get_dataset,TealDataset)
S3method(get_dataset,TealDatasetConnector)
Expand All @@ -20,6 +25,11 @@ S3method(get_dataset_label,TealDatasetConnector)
S3method(get_datasets,TealDataAbstract)
S3method(get_datasets,TealDataset)
S3method(get_datasets,TealDatasetConnector)
S3method(get_datasets,teal_data)
S3method(get_join_keys,JoinKeys)
S3method(get_join_keys,TealData)
S3method(get_join_keys,default)
S3method(get_join_keys,teal_data)
S3method(get_key_duplicates,TealDataset)
S3method(get_key_duplicates,data.frame)
S3method(get_keys,TealDataAbstract)
Expand Down Expand Up @@ -50,13 +60,14 @@ S3method(set_keys,TealDataAbstract)
S3method(set_keys,TealDataset)
S3method(set_keys,TealDatasetConnector)
S3method(to_relational_data,MultiAssayExperiment)
S3method(to_relational_data,TealData)
S3method(to_relational_data,TealDataset)
S3method(to_relational_data,TealDatasetConnector)
S3method(to_relational_data,data.frame)
S3method(to_relational_data,list)
export("col_labels<-")
export("data_label<-")
export("datanames<-")
export("get_join_keys<-")
export(as_cdisc)
export(callable_code)
export(callable_function)
Expand All @@ -67,6 +78,7 @@ export(cdisc_dataset)
export(cdisc_dataset_connector)
export(cdisc_dataset_connector_file)
export(cdisc_dataset_file)
export(cdisc_join_keys)
export(code_cdisc_dataset_connector)
export(code_dataset_connector)
export(col_labels)
Expand All @@ -75,6 +87,7 @@ export(csv_cdisc_dataset_connector)
export(csv_dataset_connector)
export(data_connection)
export(data_label)
export(datanames)
export(dataset)
export(dataset_connector)
export(dataset_connector_file)
Expand All @@ -89,6 +102,7 @@ export(get_dataname)
export(get_dataset)
export(get_dataset_label)
export(get_datasets)
export(get_join_keys)
export(get_key_duplicates)
export(get_keys)
export(get_labels)
Expand Down Expand Up @@ -118,7 +132,8 @@ export(teal_data_file)
export(to_relational_data)
export(validate_metadata)
import(shiny)
import(teal.code)
importFrom(digest,digest)
importFrom(logger,log_trace)
importFrom(shinyjs,show)
importFrom(shinyjs,useShinyjs)
importFrom(stats,setNames)
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# teal.data 0.3.0.9007

### Enhancements
* Simplified `join_key` to better support primary keys.
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
* Added subset and subset-assignment to `JoinKeySet` class to manipulate relationship pair keys _(`[` and `[<-`)_.

### Breaking changes

* Introduced new data class (`teal_data`) which replaces deprecated `TealData`. New data class becomes a standard input for whole `teal` framework.
* Deprecated `teal_data` constructor when `TealDataset`, `TealDatasetConnector` or `TealDataConnector` objects are provided. New delayed data loading functions introduced in `teal` package.
### Miscellaneous
* Specified minimal version of package dependencies.

Expand Down
1 change: 0 additions & 1 deletion R/CallableFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ CallableFunction <- R6::R6Class( # nolint
# @return nothing
refresh = function() {
if (!is.null(private$fun_name) || !identical(private$fun_name, character(0))) {

# replaced str2lang found at:
# https://rlang.r-lib.org/reference/call2.html
private$call <- as.call(
Expand Down
95 changes: 85 additions & 10 deletions R/JoinKeys.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ JoinKeys <- R6::R6Class( # nolint
return(TRUE)
}

if (xor(length(join_key_1$keys) == 0, length(join_key_2$keys) == 0) ||
!identical(sort(join_key_1$keys), sort(setNames(names(join_key_2$keys), join_key_2$keys)))) {
if (
xor(length(join_key_1$keys) == 0, length(join_key_2$keys) == 0) ||
!identical(sort(join_key_1$keys), sort(setNames(names(join_key_2$keys), join_key_2$keys)))
) {
error_message(join_key_1$dataset_1, join_key_1$dataset_2)
}
}
Expand Down Expand Up @@ -351,17 +353,18 @@ JoinKeys <- R6::R6Class( # nolint
#' @export
#'
#' @examples
#' join_keys()
#' # setting join keys
#' join_keys(
#' join_key("dataset_A", "dataset_B", c("col_1" = "col_a")),
#' join_key("dataset_A", "dataset_C", c("col_2" = "col_x", "col_3" = "col_y"))
#' )
#' join_keys(
#' join_key("dataset_A", "dataset_B", c("col_1" = "col_a"))
#' )
#' # or
#' jk <- join_keys()
#' jk["dataset_A", "dataset_B"] <- c("col_1" = "col_a")
#' jk["dataset_A", "dataset_C"] <- c("col_2" = "col_x", "col_3" = "col_y")
#'
join_keys <- function(...) {
x <- list(...)

x <- rlang::list2(...)
res <- JoinKeys$new()
if (length(x) > 0) {
res$set(x)
Expand All @@ -370,6 +373,74 @@ join_keys <- function(...) {
res
}

#' @title Getter for JoinKeys that returns the relationship between pairs of datasets
#' @param x JoinKeys object to extract the join keys
#' @param dataset_1 (`character`) name of first dataset.
#' @param dataset_2 (`character`) name of second dataset.
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
#' @export
#' @keywords internal
`[.JoinKeys` <- function(x, dataset_1, dataset_2 = dataset_1) {
checkmate::assert_string(dataset_1)
checkmate::assert_string(dataset_2)
x$get(dataset_1, dataset_2)
}

#' @rdname sub-.JoinKeys
#' @param value value to assign
#' @export
#' @keywords internal
`[<-.JoinKeys` <- function(x, dataset_1, dataset_2 = dataset_1, value) {
checkmate::assert_string(dataset_1)
checkmate::assert_string(dataset_2)
x$mutate(dataset_1, dataset_2, value)
x
}

#' @rdname join_keys
#' @details
#' `cdisc_join_keys` is a wrapper around `join_keys` that sets the default
#' join keys for CDISC datasets. It is used internally by `cdisc_data` to
#' set the default join keys for CDISC datasets.
#'
#' @export
#' @examples
#'
#' # default CDISC join keys
#' cdisc_join_keys(join_key("dataset_A", "dataset_B", c("col_1" = "col_a")), "ADTTE")
#'
cdisc_join_keys <- function(...) {
data_objects <- rlang::list2(...)

join_keys <- join_keys()
lapply(seq_along(data_objects), function(ix) {
item <- data_objects[[ix]]
name <- names(data_objects)[ix]

if ((is.null(name) || identical(trimws(name), "")) && is.character(item)) {
name <- item
} else if (checkmate::test_class(item, "JoinKeySet")) {
join_keys$set(item)
return(NULL)
} else if (
checkmate::test_multi_class(item, c("TealDataConnector", "TealDataset", "TealDatasetConnector"))
) {
return(NULL)
}

if (name %in% names(default_cdisc_keys)) {
# Set default primary keys
keys_list <- default_cdisc_keys[[name]]
join_keys[name] <- keys_list$primary

if (!is.null(keys_list$parent) && !is.null(keys_list$foreign)) {
join_keys[name, keys_list$parent] <- keys_list$foreign
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block should go into the block in line 424. The logic will be reflected better and the return(NULL) statements can be removed. The last case becomes redundant altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not true. If name is not null then previous if-else doesn't exit (don't return NULL)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

    if (checkmate::test_class(item, "JoinKeySet")) {
      join_keys$set(item)
    } else {
      if ((is.null(name) || identical(trimws(name), "")) && is.character(item)) {
        name <- item
      } 
      if (name %in% names(default_cdisc_keys)) {
        # Set default primary keys
        keys_list <- default_cdisc_keys[[name]]
        join_keys[name] <- keys_list$primary
        
        if (!is.null(keys_list$parent) && !is.null(keys_list$foreign)) {
          join_keys[name, keys_list$parent] <- keys_list$foreign
        }
      }
    }

On another note, I think using lapply like this is missing the point of lapply. A loop could actually be easier to read and we wouldn't have to consider return(NULL)s.

})

join_keys
}

# wrappers ====
#' Mutate `JoinKeys` with a new values
#'
Expand Down Expand Up @@ -425,12 +496,16 @@ mutate_join_keys.TealData <- function(x, dataset_1, dataset_2, val) { # nolint
x$mutate_join_keys(dataset_1, dataset_2, val)
}


#' Create a relationship between a pair of datasets
#'
#' @description `r lifecycle::badge("stable")`
#'
#' @details `join_key()` will create a relationship for the variables on a pair
#' of datasets.
#'
#' @inheritParams mutate_join_keys
#' @param dataset_2 (optional `character`) other dataset name. In case it is omitted, then it
#' will create a primary key for `dataset_1`.
#' @param keys (optionally named `character`) where `names(keys)` are columns in `dataset_1`
#' with relationship to columns of `dataset_2` given by the elements in `keys`.
#' If `names(keys)` is `NULL` then the same column names are used for both `dataset_1`
Expand All @@ -441,7 +516,7 @@ mutate_join_keys.TealData <- function(x, dataset_1, dataset_2, val) { # nolint
#' @seealso [join_keys()]
#'
#' @export
join_key <- function(dataset_1, dataset_2, keys) {
join_key <- function(dataset_1, dataset_2 = dataset_1, keys) {
checkmate::assert_string(dataset_1)
checkmate::assert_string(dataset_2)
checkmate::assert_character(keys, any.missing = FALSE)
Expand Down
Loading