-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial support for names(teal_data)
- Loading branch information
1 parent
eca9695
commit eb24644
Showing
17 changed files
with
234 additions
and
202 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,53 @@ | ||
#' Names of data sets in `teal_data` object | ||
#' | ||
#' Functions to get the names of a `teal_data` object. | ||
#' The names are extrapolated from the objects in the `qenv` environment and | ||
#' are not stored statically, unlike the normal behavior of `names()` function. | ||
#' | ||
#' Objects named with a `.` (dot) prefix will be ignored and not returned, | ||
#' unless `all.names` parameter is set to `TRUE`. | ||
#' | ||
#' @param x A (`teal_data`) object to access or modify. | ||
#' @param all.names (`logical(1)`) that specifies whether to include hidden | ||
#' objects. | ||
#' @param value Does nothing as the names assignment is not supported. | ||
#' | ||
#' @return A character vector of names. | ||
#' | ||
#' @examples | ||
#' td <- teal_data(iris = iris) | ||
#' td <- within(td, mtcars <- mtcars) | ||
#' names(td) | ||
#' | ||
#' td <- within(td, .CO2 <- CO2) | ||
#' names(td) | ||
#' | ||
#' @export | ||
names.teal_data <- function(x, all.names = FALSE) { | ||
checkmate::assert_flag(all.names) | ||
# Call method on qenv class | ||
names_x <- utils::getS3method("names", class = "qenv")(x, all.names) | ||
.get_sorted_names(names_x, join_keys(x), teal.code::get_env(x)) | ||
} | ||
|
||
#' @rdname names.teal_data | ||
#' @export | ||
`names.teal_data<-` <- function(x, value) { | ||
warning("`names(x) <- value` assignment does nothing for teal_data objects") | ||
x | ||
} | ||
|
||
#' @keywords internal | ||
.get_sorted_names <- 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, all.names = TRUE)), | ||
datanames | ||
) | ||
} |
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.