Skip to content

Commit

Permalink
Merge branch 'main' into roxygen-md
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy authored Jul 11, 2023
2 parents 826ba7d + 7375941 commit 07c9bc9
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 14 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Imports:
snakecase (>= 0.9.2),
stringi,
stringr,
tidyr (>= 0.7.0),
tidyr (>= 1.0.0),
tidyselect (>= 1.0.0)
License: MIT + file LICENSE
Suggests:
dbplyr,
knitr,
Expand Down
2 changes: 1 addition & 1 deletion R/adorn_title.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' mtcars %>%
#' group_by(gear, am) %>%
#' summarise(avg_mpg = mean(mpg), .groups = "drop") %>%
#' spread(gear, avg_mpg) %>%
#' pivot_wider(names_from = am, values_from = avg_mpg) %>%
#' adorn_rounding() %>%
#' adorn_title("top", row_name = "Gears", col_name = "Cylinders")
adorn_title <- function(dat, placement = "top", row_name, col_name) {
Expand Down
7 changes: 6 additions & 1 deletion R/tabyl.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ tabyl_2way <- function(dat, var1, var2, show_na = TRUE, show_missing_levels = TR
tabl[2][is.na(tabl[2])] <- "NA_"
tabl[2][tabl[2] == ""] <- "emptystring_"
result <- tabl %>%
tidyr::spread(!!var2, "tabyl_2way_n", fill = 0)
tidyr::pivot_wider(
names_from = !!var2,
values_from = "tabyl_2way_n",
values_fn = ~ dplyr::coalesce(.x, 0L),
names_sort = TRUE
)
if ("emptystring_" %in% names(result)) {
result <- result[c(setdiff(names(result), "emptystring_"), "emptystring_")]
if (getOption("tabyl.emptystring", TRUE) & interactive()) {
Expand Down
2 changes: 1 addition & 1 deletion man/adorn_title.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added pkgdown/favicon/apple-touch-icon-120x120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/apple-touch-icon-152x152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/apple-touch-icon-180x180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/apple-touch-icon-60x60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/apple-touch-icon-76x76.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/favicon.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/testthat/test-adorn-title.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test_that("name overrides work", {
test_that("non-tabyls are treated correctly", {
non_tab <- mtcars %>%
dplyr::count(gear, cyl) %>%
tidyr::spread(gear, n)
tidyr::pivot_wider(names_from = gear, values_from = n)
expect_error(adorn_title(non_tab), "When input is not a data.frame of class tabyl, a value must be specified for the col_name argument")

expect_equal(
Expand Down Expand Up @@ -111,7 +111,7 @@ test_that("for printing purposes: tabyl class stays tabyl, data.frame stays data
mtcars %>%
dplyr::group_by(cyl, am) %>%
dplyr::summarise(mean_mpg = mean(mpg)) %>%
tidyr::spread(am, mean_mpg)
tidyr::pivot_wider(names_from = am, values_from = mean_mpg)

# handles tibble input
expect_s3_class(
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-adorn-totals.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ ct_2 <-
mtcars %>%
dplyr::group_by(cyl, gear) %>%
dplyr::tally() %>%
tidyr::spread(gear, n)
tidyr::pivot_wider(names_from = gear, values_from = n)
df1 <- data.frame(x = c(1, 2), y = c(NA, 4))

test_that("grouped_df gets ungrouped and succeeds", {
ct_2 <-
mtcars %>%
dplyr::group_by(cyl, gear) %>%
dplyr::tally() %>%
tidyr::spread(gear, n)
tidyr::pivot_wider(names_from = gear, values_from = n)
expect_equal(
ct_2 %>% adorn_totals(),
ct_2 %>% dplyr::ungroup() %>% adorn_totals()
Expand Down
9 changes: 7 additions & 2 deletions tests/testthat/test-tabyl-classifiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ a <- mtcars %>%

b <- mtcars %>%
dplyr::count(cyl, carb) %>%
tidyr::spread(carb, n, fill = 0) %>%
tidyr::pivot_wider(
names_from = carb,
values_from = n,
values_fill = 0,
names_sort = TRUE
) %>%
as.data.frame() # for comparison purposes, remove the tbl_df aspect


test_that("as_tabyl works on result of a non-janitor count/spread", {
test_that("as_tabyl works on result of a non-janitor count/pivot_wider", {
expect_equal(
as_tabyl(a),
as_tabyl(b, 2, "cyl", "carb")
Expand Down
4 changes: 2 additions & 2 deletions vignettes/tabyls.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ cases %>%
Here's a more complex example that uses a data.frame of means, not counts. We create a table containing the mean of a 3rd variable when grouped by two other variables, then use `adorn_` functions to round the values and append Ns. The first part is pretty straightforward:

```{r more_non_tabyls, warning = FALSE, message = FALSE}
library(tidyr) # for spread()
library(tidyr) # for pivot_wider()
mpg_by_cyl_and_am <- mtcars %>%
group_by(cyl, am) %>%
summarise(mpg = mean(mpg), .groups = "drop") %>%
spread(am, mpg)
pivot_wider(names_from = am, values_from = mpg)
mpg_by_cyl_and_am
```
Expand Down
4 changes: 2 additions & 2 deletions vignettes/tabyls.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ grouped by two other variables, then use `adorn_` functions to round the
values and append Ns. The first part is pretty straightforward:

``` r
library(tidyr) # for spread()
library(tidyr) # for pivot_wider()
mpg_by_cyl_and_am <- mtcars %>%
group_by(cyl, am) %>%
summarise(mpg = mean(mpg), .groups = "drop") %>%
spread(am, mpg)
pivot_wider(names_from = am, values_from = mpg)

mpg_by_cyl_and_am
#> # A tibble: 3 × 3
Expand Down

0 comments on commit 07c9bc9

Please sign in to comment.