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

Adds names() function and deprecates datanames() #347

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

averissimo
Copy link
Contributor

@averissimo averissimo commented Oct 28, 2024

Pull Request

Blockers

Changes description

  • Adds names() function
    • Setter is implemented but throws warning (does nothing)
  • Deprecates datanames() getter and setter
  • Adapt tests to new API
  • Update NEWS
  • Review documentation
  • Review vignettes

@gogonzo gogonzo self-assigned this Oct 29, 2024
#' @rdname datanames
#' @export
#' @keywords internal
`names<-.teal_data` <- function(x, value) {
Copy link
Contributor

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

#'
#' @export
names.teal_data <- function(x) {
names_x <- names(as.environment(x))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using names in body which will return all objects, including with dot prefix.

I don't think it makes sense to use ls(x, all.names = FALSE) as that changes the way the function works.

We could add support to ls via some trickery, but I'm leaning against it, mainly as it will appear as masking ls when loading the package.

#' @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, ...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 teal summary table (as that should be ordered with this behavior in mind)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Don't use @datanames anymore
2 participants