-
Notifications
You must be signed in to change notification settings - Fork 26
Add log to dplyr function ungroup() #33
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
Changes from 11 commits
578c87f
aaf9c09
8612152
a4c82b1
d281bbb
1444cfc
78de7b9
532733a
687fe0b
bbc05ea
06f1565
baae929
3e70eea
39c624f
9c1390a
dbe5ff5
ab93036
51bec8a
205134a
2162f4f
87fbcd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
Package: tidylog | ||
Type: Package | ||
Title: Logging for 'dplyr' and 'tidyr' Functions | ||
Title: Logging for 'dplyr' and 'tidyr' functions | ||
Version: 0.2.0.9000 | ||
Authors@R: person("Benjamin", "Elbers", email = "[email protected]", | ||
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5392-3448")) | ||
Authors@R: c( | ||
person("Benjamin", "Elbers", email = "[email protected]", | ||
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5392-3448")), | ||
person("Damiano", "Oldoni", email = "[email protected]", | ||
role = c("aut", "ctb"), comment = c(ORCID = "0000-0003-3445-7562")) | ||
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. please use just "ctb" here 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. I am very sorry: I am definitely not the author! A copy paste error. |
||
) | ||
Description: Provides feedback about 'dplyr' and 'tidyr' operations. | ||
License: MIT + file LICENSE | ||
Imports: dplyr, tidyr, glue, clisymbols | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#' Wrapper around dplyr::ungroup that prints information about the operation | ||
#' | ||
#' @param .data a tbl; see \link[dplyr]{group_by} | ||
#' @param ... see \link[dplyr]{group_by} | ||
#' @return see \link[dplyr]{group_by} | ||
#' @examples | ||
#' mtcars <- group_by(mtcars, am, cyl) | ||
#' #> group_by: 2 grouping variables (am, cyl) | ||
#' mtcars <- ungroup(mtcars) | ||
#' #> ungroup: no grouping variables left | ||
#' @import dplyr | ||
#' @export | ||
ungroup <- function(.data, ...) { | ||
log_ungroup(.data, .fun = dplyr::ungroup, .funname = "ungroup", ...) | ||
} | ||
|
||
|
||
log_ungroup <- function(.data, .fun, .funname, ...) { | ||
newdata <- .fun(.data, ...) | ||
if (!"data.frame" %in% class(.data) | !should_display()) { | ||
return(newdata) | ||
} | ||
display(glue::glue( | ||
"{.funname}: no grouping variables left")) | ||
newdata | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,9 +56,10 @@ summary <- mtcars %>% | |
mutate(mpg_round = round(mpg)) %>% | ||
group_by(cyl, mpg_round, am) %>% | ||
tally() %>% | ||
filter(n >= 1) | ||
filter(n >= 1) %>% | ||
ungroup() | ||
``` | ||
Here, it might have been accidental that the last `filter` command had no effect. | ||
Here, it might have been accidental that the `filter` command had no effect. | ||
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. please leave as is, or change to "second" 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. Yes, you are right: it refers to the fact that there are two filters, indeed. |
||
|
||
## Installation | ||
|
||
|
@@ -154,7 +155,7 @@ a <- mtcars %>% | |
|
||
b <- iris %>% | ||
group_by(Species) %>% | ||
summarize_all(list(~min, ~max)) | ||
summarize_all(list(min, max)) | ||
``` | ||
|
||
### tally, count, add_tally, add_count | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
library("dplyr") | ||
library("tidyr") | ||
library("tidylog") | ||
context("test_filter") | ||
|
||
test_that("filter", { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
library("dplyr") | ||
library("tidyr") | ||
library("tidylog") | ||
context("test_gather") | ||
|
||
test_that("gather", { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
library("dplyr") | ||
library("tidylog") | ||
context("test_group_by") | ||
|
||
test_that("group_by", { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
library("dplyr") | ||
library("tidylog") | ||
context("test_mutate") | ||
|
||
test_that("mutate", { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
library("dplyr") | ||
library("tidylog") | ||
context("test_select") | ||
|
||
test_that("select", { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
library("dplyr") | ||
library("tidylog") | ||
context("test_summarize") | ||
|
||
test_that("summarize", { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
context("test_ungroup") | ||
|
||
test_that("ungroup", { | ||
expect_message({ | ||
out <- tidylog::ungroup(mtcars, mpg) | ||
}) | ||
expect_equal(dplyr::is.grouped_df(out), FALSE) | ||
|
||
expect_silent({ | ||
out <- dplyr::ungroup(mtcars, mpg) | ||
}) | ||
}) |
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.
not a typo
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.
Done: 3e70eea