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

topological_sort for datanames(teal_data()) #318

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c8a448c
test for ; case
m7pr Jan 18, 2024
a942d60
merge
m7pr Jan 18, 2024
d276477
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr Jan 22, 2024
d2727d4
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr Jan 24, 2024
3fa1a8d
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr Jan 26, 2024
b4d1d9f
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr Feb 1, 2024
fc2e59e
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr Feb 5, 2024
484915e
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr Feb 6, 2024
a53e3a1
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr Feb 22, 2024
3c98a37
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr Mar 20, 2024
f195d1c
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr May 8, 2024
c0d8065
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr May 14, 2024
4eeca16
Merge branch 'main' of https://github.com/insightsengineering/teal.data
m7pr Jul 30, 2024
5cdb5f7
WIP - topological sort for datanames
m7pr Jul 30, 2024
621cfb5
Update R/teal_data-datanames.R
m7pr Jul 31, 2024
96228a0
add two tests for topological_sort
m7pr Jul 31, 2024
784965b
WIP - topological sort for datanames
m7pr Jul 31, 2024
2cbff27
Merge branch 'topological_sort@669_insertUI@main' of https://github.c…
m7pr Jul 31, 2024
3050093
Update R/teal_data-datanames.R
m7pr Jul 31, 2024
c8ebd82
[skip style] [skip vbump] Restyle files
github-actions[bot] Jul 31, 2024
8a84286
datanames() test for join_keys set during teal_data creation
m7pr Jul 31, 2024
e58c298
Merge branch 'topological_sort@669_insertUI@main' of https://github.c…
m7pr Jul 31, 2024
ee389a5
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Jul 31, 2024
f6be311
set safely
gogonzo Jul 31, 2024
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Collate:
'cdisc_data.R'
'data.R'
Expand Down
1 change: 1 addition & 0 deletions R/join_keys.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ join_keys.teal_data <- function(...) {
#' join_keys(td)
`join_keys<-.teal_data` <- function(x, value) {
join_keys(x@join_keys) <- value
datanames(x) <- x@datanames # datanames fun manages some exceptions
x
}

Expand Down
2 changes: 2 additions & 0 deletions R/teal_data-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ new_teal_data <- function(data,
new_env <- rlang::env_clone(list2env(data), parent = parent.env(.GlobalEnv))
lockEnvironment(new_env, bindings = TRUE)

datanames <- .get_sorted_datanames(datanames = datanames, join_keys = join_keys, env = env)

methods::new(
"teal_data",
env = new_env,
Expand Down
18 changes: 17 additions & 1 deletion R/teal_data-datanames.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,27 @@ setMethod("datanames", signature = "qenv.error", definition = function(x) {
setGeneric("datanames<-", function(x, value) standardGeneric("datanames<-"))
setMethod("datanames<-", signature = c("teal_data", "character"), definition = function(x, value) {
checkmate::assert_subset(value, names(x@env))
x@datanames <- value
x@datanames <- .get_sorted_datanames(datanames = value, join_keys = x@join_keys, env = x@env)
methods::validObject(x)
x
})
setMethod("datanames<-", signature = c("qenv.error", "character"), definition = function(x, value) {
methods::validObject(x)
x
})


#' @keywords internal
.get_sorted_datanames <- function(datanames, join_keys, env) {
child_parent <- sapply(
datanames,
function(name) parent(join_keys, name),
USE.NAMES = TRUE,
simplify = FALSE
)

union(
intersect(unlist(topological_sort(child_parent)), ls(env)),
datanames
)
}
41 changes: 41 additions & 0 deletions tests/testthat/test-datanames.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,44 @@
qec <- qe
testthat::expect_identical(qe, qec)
})

# topological_order ----

testthat::test_that("datanames are set in topological in constructor if join_keys are specified", {
data <-
teal_data(b = data.frame(), a = data.frame(), join_keys = join_keys(join_key("a", "b", "id")))
testthat::expect_identical(
datanames(data),
c("a", "b")
)
})

testthat::test_that("datanames return topological order of datasets once join_keys are specified", {
data <- within(teal_data(), {
ADTTE <- teal.data::rADTTE

Check warning on line 58 in tests/testthat/test-datanames.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-datanames.R,line=58,col=5,[object_name_linter] Variable and function name style should match snake_case or symbols.
iris <- iris
ADSL <- teal.data::rADSL

Check warning on line 60 in tests/testthat/test-datanames.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-datanames.R,line=60,col=5,[object_name_linter] Variable and function name style should match snake_case or symbols.
})
datanames(data) <- c("ADTTE", "iris", "ADSL")
join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")]
testthat::expect_identical(
datanames(data),
c("ADSL", "ADTTE", "iris")
)
})

testthat::test_that("datanames return topological order of datasets after datanames are caled after join_keys", {
data <- within(teal_data(), {
ADTTE <- teal.data::rADTTE

Check warning on line 72 in tests/testthat/test-datanames.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-datanames.R,line=72,col=5,[object_name_linter] Variable and function name style should match snake_case or symbols.
iris <- iris
ADSL <- teal.data::rADSL

Check warning on line 74 in tests/testthat/test-datanames.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-datanames.R,line=74,col=5,[object_name_linter] Variable and function name style should match snake_case or symbols.
})

join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")]
datanames(data) <- c("ADTTE", "iris", "ADSL")

testthat::expect_identical(
datanames(data),
c("ADSL", "ADTTE", "iris")
)
})
Loading