-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Simplifies data constructor for primary keys in join_keys
#179
Changes from all commits
d9d72d5
df1f573
4ed8daa
f3abc93
508e19e
fd2b12f
0c6184d
0516592
f2a311b
0e4edcf
66f233d
e1b72c7
87b7334
ceb7db6
7cfc05d
6f70c19
1e5531a
98eedbd
45e57e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -33,29 +33,38 @@ | |||||||||||
#' ) | ||||||||||||
#' ) | ||||||||||||
cdisc_data <- function(..., | ||||||||||||
join_keys = teal.data::join_keys(), | ||||||||||||
join_keys = teal.data::cdisc_join_keys(...), | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this moment Previously There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this, as we discussed in the call I've added this and refactored the code to remove repetitive code in |
||||||||||||
code = "", | ||||||||||||
check = FALSE) { | ||||||||||||
data_objects <- list(...) | ||||||||||||
deprecated_join_keys_extract(data_objects, join_keys) | ||||||||||||
teal_data(..., join_keys = join_keys, code = code, check = check) | ||||||||||||
} | ||||||||||||
|
||||||||||||
# todo: is it really important? - to remove | ||||||||||||
if (inherits(join_keys, "JoinKeySet")) { | ||||||||||||
join_keys <- teal.data::join_keys(join_keys) | ||||||||||||
} | ||||||||||||
|
||||||||||||
#' Extrapolate parents from `TealData` classes | ||||||||||||
#' | ||||||||||||
#' `r lifecycle::badge("deprecated")` | ||||||||||||
#' | ||||||||||||
#' note: This function will be removed once the following classes are defunct: | ||||||||||||
#' `TealDataConnector`, `TealDataset`, `TealDatasetConnector` | ||||||||||||
#' | ||||||||||||
#' @keywords internal | ||||||||||||
deprecated_join_keys_extract <- function(data_objects, join_keys) { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to add this condition to skip
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Thanks! I noticed this too when testing. Added on 9630699 (negated though) if (
!checkmate::test_list(
data_objects,
types = c("TealDataConnector", "TealDataset", "TealDatasetConnector")
)
) {
return(join_keys)
} |
||||||||||||
if ( | ||||||||||||
checkmate::test_list(data_objects, types = c("TealDataConnector", "TealDataset", "TealDatasetConnector")) | ||||||||||||
) { | ||||||||||||
lifecycle::deprecate_warn( | ||||||||||||
when = "0.3.1", | ||||||||||||
"cdisc_data( | ||||||||||||
data_objects = 'should use data directly. Using TealDatasetConnector and TealDataset is deprecated.' | ||||||||||||
)" | ||||||||||||
!checkmate::test_list( | ||||||||||||
data_objects, | ||||||||||||
types = c("TealDataConnector", "TealDataset", "TealDatasetConnector") | ||||||||||||
) | ||||||||||||
update_join_keys_to_primary(data_objects, join_keys) | ||||||||||||
) { | ||||||||||||
return(join_keys) | ||||||||||||
} | ||||||||||||
# TODO: check if redundant with same call in teal_data body | ||||||||||||
update_join_keys_to_primary(data_objects, join_keys) | ||||||||||||
|
||||||||||||
new_parents_fun <- function(data_objects) { | ||||||||||||
lapply(data_objects, function(x) { | ||||||||||||
new_parents_fun <- function(data_objects) { | ||||||||||||
lapply( | ||||||||||||
data_objects, | ||||||||||||
function(x) { | ||||||||||||
if (inherits(x, "TealDataConnector")) { | ||||||||||||
unlist(new_parents_fun(x$get_items()), recursive = FALSE) | ||||||||||||
} else { | ||||||||||||
|
@@ -66,40 +75,27 @@ cdisc_data <- function(..., | |||||||||||
) | ||||||||||||
) | ||||||||||||
} | ||||||||||||
}) | ||||||||||||
} | ||||||||||||
|
||||||||||||
new_parents <- unlist(new_parents_fun(data_objects), recursive = FALSE) | ||||||||||||
|
||||||||||||
names(new_parents) <- unlist(lapply(data_objects, function(x) { | ||||||||||||
if (inherits(x, "TealDataConnector")) { | ||||||||||||
lapply(x$get_items(), function(y) y$get_dataname()) | ||||||||||||
} else { | ||||||||||||
x$get_datanames() | ||||||||||||
} | ||||||||||||
})) | ||||||||||||
|
||||||||||||
if (is_dag(new_parents)) { | ||||||||||||
stop("Cycle detected in a parent and child dataset graph.") | ||||||||||||
} | ||||||||||||
join_keys$set_parents(new_parents) | ||||||||||||
join_keys$update_keys_given_parents() | ||||||||||||
) | ||||||||||||
} | ||||||||||||
|
||||||||||||
x <- TealData$new(..., check = check, join_keys = join_keys) | ||||||||||||
new_parents <- unlist(new_parents_fun(data_objects), recursive = FALSE) | ||||||||||||
|
||||||||||||
if (length(code) > 0 && !identical(code, "")) { | ||||||||||||
x$set_pull_code(code = code) | ||||||||||||
names(new_parents) <- unlist(lapply(data_objects, function(x) { | ||||||||||||
if (inherits(x, "TealDataConnector")) { | ||||||||||||
lapply(x$get_items(), function(y) y$get_dataname()) | ||||||||||||
} else { | ||||||||||||
x$get_datanames() | ||||||||||||
} | ||||||||||||
})) | ||||||||||||
|
||||||||||||
x$check_reproducibility() | ||||||||||||
x$check_metadata() | ||||||||||||
x | ||||||||||||
} else { | ||||||||||||
if (!checkmate::test_names(names(data_objects), type = "named")) { | ||||||||||||
stop("Dot (`...`) arguments on `teal_data()` must be named.") | ||||||||||||
} | ||||||||||||
new_teal_data(data = data_objects, code = code, keys = join_keys) | ||||||||||||
if (is_dag(new_parents)) { | ||||||||||||
stop("Cycle detected in a parent and child dataset graph.") | ||||||||||||
} | ||||||||||||
join_keys$set_parents(new_parents) | ||||||||||||
join_keys$update_keys_given_parents() | ||||||||||||
|
||||||||||||
join_keys | ||||||||||||
} | ||||||||||||
|
||||||||||||
#' Load `TealData` object from a file | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
CDISC | ||
Forkers | ||
Hoffmann | ||
Pre | ||
Reproducibility | ||
SCDA | ||
UI | ||
cloneable | ||
Forkers | ||
formatters | ||
funder | ||
Getter | ||
Hoffmann | ||
iteratively | ||
JoinKeys | ||
Pre | ||
pre | ||
repo | ||
Reproducibility | ||
reproducibility | ||
SCDA | ||
UI |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that we need
cdisc_join_keys
also inddl
constructor. It means that we won't have a named list of object - we can only have names of datasets.It means we need a cdisc_join_keys function which can just accept names of datasets. When I look at the function body,
name
(datanames) is exactly what this function needs. So I think that maybe we should havedatanames
argument instead of...
? And do followingIn above, in case of old-classes list will be unnamed so function will return NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the function actually takes strings in
...
and parses them as if they are named lists.. the following calls are valid (as of now)But we can also use your suggestion:
cdisc_data(..., join_keys = cdisc_join_keys(names(...))
WDYT?