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

Implement distinct() #17

Closed
msberends opened this issue May 4, 2020 · 2 comments
Closed

Implement distinct() #17

msberends opened this issue May 4, 2020 · 2 comments
Labels
feature request New feature or request
Milestone

Comments

@msberends
Copy link
Contributor

Suggestion:

distinct <- function(.data, ..., .keep_all = FALSE) {
  check_is_dataframe(.data)
  UseMethod("distinct")
}

distinct.default <- function(.data, ..., .keep_all = FALSE) {
  names <- rownames(.data)
  rownames(.data) <- NULL
  if (length(deparse_dots(...)) == 0) {
    selected <- .data
  } else {
    selected <- select(.data, ...)
  }
  rows <- as.integer(rownames(unique(selected)))
  if (isTRUE(.keep_all)) {
    res <- .data[rows, , drop = FALSE]
  } else {
    res <- selected[rows, , drop = FALSE]
  }
  rownames(res) <- names[rows]
  res
}

distinct.grouped_data <- function(.data, ..., .keep_all = FALSE) {
  apply_grouped_function(.data, "distinct", ..., .keep_all = .keep_all)
}

I cannot get the grouped version to work to also include the group variables. It now only returns the distinct variable if set...


Another idea - You should mention on your README that this package is a great, great idea for package developers that do not want to be dependent on dplyr (as it changes too often for sustainable pkg development), but do want to code using dplyr methods. For those users you could also create an extra raw syntax file with all your functions without roxygen parts (remove all lines starting with #') and your name on it, so they can copy it to their package.

@nathaneastwood nathaneastwood added the feature request New feature or request label May 4, 2020
@nathaneastwood
Copy link
Owner

Thanks for the code 🙂 I’ll take a look when I get a chance.

Another idea - You should mention on your README that this package is a great, great idea for package developers that do not want to be dependent on dplyr (as it changes too often for sustainable pkg development), but do want to code using dplyr methods.

Yes and no. It’s good because there are much fewer dependencies. But the aim of poorman is to replicate dplyr as closely as possible. So any changes seen in dplyr are likely to make their way into poorman at some point.

For those users you could also create an extra raw syntax file with all your functions without roxygen parts (remove all lines starting with #') and your name on it, so they can copy it to their package.

Hmm, I think it might just be easier to depend on poorman to be honest. As more features get added, the code is likely to get more complex. Given there will only ever be the one package to depend on with poorman, I don’t think it’s too much of an issue.

@msberends
Copy link
Contributor Author

👍

nathaneastwood added a commit that referenced this issue May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants