-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Adds names()
function and deprecates datanames()
#347
base: main
Are you sure you want to change the base?
Changes from all commits
eb24644
b3fe731
8406a83
cd5a938
4f92467
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#' 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. | ||
#' | ||
#' @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) { | ||
names_x <- names(as.environment(x)) | ||
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. Using I don't think it makes sense to use We could add support to #' @export
ls <- function(x, ...) {
UseMethod("ls")
}
#' @export
ls.teal_data <- function(x, ...) {
names_x <- base::ls(as.environment(x), ...)
.get_sorted_names(names_x, join_keys(x), as.environment(x))
}
#' @export
ls.default <- function(x, ...) {
base::ls(x, ...)
} 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. Note that by using names here, we need to make some changes to |
||
.get_sorted_names(names_x, join_keys(x), as.environment(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 | ||
) | ||
} |
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 acknowledge introducing
names<-
just to deprecate itself