-
-
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 JoinKeys
from R6 to S3 list-like object
#184
Conversation
JoinKeys
from R6 to S3 list-like object
@averissimo
|
@gogonzo the
As it is, the code on your comment should NOW output what you expect. jk <- join_keys(
join_key("df1", "df1", c("id", "id2")),
join_key("df1", "df2", c("id" = "id")),
join_key("df1", "df3", c("id" = "id")),
join_key("df2", "df2", c("id", "id2")),
join_key("df2", "df3", c("id", "id2")),
join_key("df3", "df3", c("id", "id2"))
)
# jk <- join_keys(jk) # removed this with my latest push (as R6 class was completely removed)
inherits(jk, "list")
#> [1] TRUE
jk[["df1"]]
#> $df1
#> id id2
#> "id" "id2"
#>
#> $df2
#> id
#> "id"
#>
#> $df3
#> id
#> "id" |
The See first comment (header?) for list of notable changes |
@averissimo This is no longer a caveat, right?
|
@vedhav you are right! I removed that from the comment |
@gogonzo can you give some context on using empty name on pairs? # From tests
# set key on non-empty variable name equal to ""
jk <- mutate_join_keys(join_keys(), "d1", "d2", c("A" = "B", "C" = ""))
expect_equal(jk["d1", "d2"], setNames(c("B", ""), c("A", "C"))) Previous and current implementation break symmetry. Do we need to support empty keys? If not then my suggestion is to either take the name, or if there is no name, throw an error mutate_join_keys(join_keys(), "d1", "d2", c("A" = "B", "C" = ""))
#> A JoinKeys object containing foreign keys between 2 datasets:
#> $d1
#> $d1$d2
#> A C
#> "B" ""
#>
#>
#> $d2
#> $d2$d1
#> B
#> "A" "C"
mutate_join_keys(join_keys(), "d2", "d1", setNames(c("B" = "A", "C"), c("B", "")))
#> A JoinKeys object containing foreign keys between 2 datasets:
#> $d1
#> $d1$d2
#> A C
#> "B" "C"
#>
#>
#> $d2
#> $d2$d1
#> B C
#> "A" "C" |
Code Coverage Summary
Diff against main
Results for commit: cd4b2ca Minimum allowed coverage is ♻️ This comment has been updated with latest results |
Yup, I think it was just a consequence of having named (for
Yes, I think for consistency reason it could be always named even if both datasets share the same key name. |
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 think its exactly what we want, but little too much in my opinion. There are few functions exported which are not needed at all. I also think that [
should return JoinKeys
object not a list for single dataset.
@gogonzo made a bunch of changes in response to your review. Check out the resolved conversation for the changes and I left some conversations that have follow-ups as unresolved.
So I'm changing the behaviour of |
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.
first look, non-exhaustive
@insightsengineering/nest-core-dev BLUF: should we keep Context: I'm having second thoughts about part of the new API of In particular: Why? Initially I thought it was a needed limitation with working along with 🔴 Why is this a problem: It breaks with the expected behavior on R (such as 🟠 Reasons to keep? I find it very clean for app developers to use for consecutive operations, but requires some adjusting. It is also slighlty easier to read the code than the subset assigment
🟢 Suggestion(s):
|
This confused me for the better part of today. But, once I got the hang of it I started to like this because it's such a simple way of creating join keys. Creating data and join keys is the main task for the app developers and I believe that just learning this one function and getting to know what it does should empower them to build quicker teal apps. They might have trouble building their first or second teal app but aftewards it's quicker and easier imo. |
Since the new join keys class is a list and we use this fact to have usual list mechanics, I would rather not depart from that. |
@@ -31,7 +31,7 @@ | |||
#' }) | |||
#' | |||
cdisc_data <- function(..., | |||
join_keys = teal.data::cdisc_join_keys(...), | |||
join_keys = teal.data::default_cdisc_join_keys[names(rlang::list2(...))], |
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 don't think this is a good-looking default value.
I suggest to define the function with cdisc_data(..., join_keys, code = character(0), check = FALSE)
and have join_keys
default to teal.data::default_cdisc_join_keys[names(rlang::list2(...))]
if missing.
R/teal_data.R
Outdated
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.
deprecate check
argument?
Co-authored-by: Aleksander Chlebowski <[email protected]> Signed-off-by: André Veríssimo <[email protected]>
fixes #842 part of insightsengineering/nestdevs-tasks#41 insightsengineering/teal.data#184 - [x] add thenews section for change. - [x] update the examples in the documentation to pass teal_data. - [x] update join_keys calls once the pull request is completed at insightsengineering/teal.data#184. - [x] Revise and update the vignettes accordingly. - [ ] make version bump once insightsengineering/teal.data#184. is merged. --------- Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: vedhav <[email protected]>
) Related to [teal.data PR insightsengineering#184](insightsengineering/teal.data#184) Make changes to `teal` because of the refactor to the JoinKeys class from R6 to S3. --------- Signed-off-by: Vedha Viyash <[email protected]> Co-authored-by: André Veríssimo <[email protected]> Co-authored-by: Aleksander Chlebowski <[email protected]> Co-authored-by: go_gonzo <[email protected]>
fixes #243 part of insightsengineering/nestdevs-tasks#41 insightsengineering/teal.data#184 - [x] add the news section for change. - [x] update the examples in the documentation to pass teal_data. - [x] update join_keys calls once the pull request is completed at insightsengineering/teal.data#184. - [x] Revise and update the vignettes accordingly. - [ ] make version bump once insightsengineering/teal.data#184. is merged. --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: vedhav <[email protected]>
Pull Request
🏗️ WIP
Breaking changes:
join_keys(obj) <- list(join_key(...), ...)
merge_join_keys
: can be done in other ways:join_keys(jk) <- join_keys(...)
(was r6$merge(x,y)`)split_join_keys
: Not relevant (wasr6$split()
)get_join_key
: Can be done with[
or[[
(wasr6$get(...)
)NULL
instead ofcharacter(0)
jk["idx"]
will output a join_key with all symmetric keys (if there are any)Notable changes:
⇒ New class is an extension of a
list
.obj[[dataset_1]][[dataset_2]]
⇒
JoinKeys
mutations are no longer done by memory referencejoin_keys(x) <- ...
tries to minimize this, butmutate_join_key
method and others may need to re-assign the join_keys.⇒ All previous tests were converted and pass (this adds 1% to code coverage)
⇒ Setter can be used multiple times
join_keys(obj) <- list(join_key(...), ...)
join_keys(obj)["ds1", "ds2"] <- "id"
How to use?
TODO
join_keys()
join_keys_obj
instead ofjoin_keys
that overwrites theteal.data::join_keys
functionJoinKeys$private$.keys
public and private related methodsJoinKeys$private$parents
public and private related methodsget_join_keys
instances with constructorJoinKeys
JoinKeys
R6 classPlaceholder
class name with JoinKeysjoin_keys()
instead of internalnew_join_keys()
get_join_keys()
and others calls in other packagesJoinKeys
related changes due to refactor teal.slice#486 (@vedhav)JoinKeys
related changes due to refactor teal.transform#160 (@vedhav)JoinKeys
related changes due to refactor teal#958 (@vedhav)teal_data
instead ofTealData
teal.modules.clinical#853 (@kartikeyakirar)teal_data
instead ofTealData
teal.goshawk#245 (@kartikeyakirar)teal_data
instead ofTealData
teal.modules.general#597 (@vedhav)teal.data
, other teal.* packagesdata_extract_spec
NEWS.md
join_keys
andjoin_key_set
c.join_keys
[ds1, ds2]
and[[ds1, ds2]]
names<-.join_keys
Detect changes and apply symmetryDropjoin_keys.join_keys()
getter of itself