-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update README, fix examples for gather/spread
- Loading branch information
Showing
8 changed files
with
117 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# 0.1.0.9000 | ||
- wrap new functions for tidyr::gather() and tidyr::spread() | ||
- do not report negative NA (#18) | ||
- wrap new functions for tidyr::gather() and tidyr::spread() (thanks @WilDoane) | ||
- use clisymbols for ellipsis | ||
- add number of remaining rows to filter (#23) | ||
- bugfix: do not report negative NA (#18) | ||
- bugfix: avoid partial matching (closes #26) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#' Wrapper around tidyr::gather | ||
#' that prints information about the operation | ||
#' | ||
#' @param .data a tbl; see \link[tidyr]{gather} | ||
#' @param ... see \link[tidyr]{gather} | ||
#' @return see \link[tidyr]{gather} | ||
#' @examples | ||
#' # create id | ||
#' mtcars$id <- 1:nrow(mtcars) | ||
#' gathered <- gather(mtcars, "col", "data", -id) | ||
#' #> gather: reorganized (mpg, cyl, disp, hp, drat, …) into (col, data) [was 32x12, now 352x3] | ||
#' @import tidyr | ||
#' @export | ||
gather <- function(.data, ...) { | ||
log_gather(.data, .fun = tidyr::gather, .funname = "gather", ...) | ||
} | ||
|
||
log_gather <- function(.data, .fun, .funname, ...) { | ||
newdata <- .fun(.data, ...) | ||
|
||
if (!"data.frame" %in% class(.data) | !should_display()) { | ||
return(newdata) | ||
} | ||
|
||
newcols <- setdiff(names(newdata), names(.data)) | ||
oldcols <- setdiff(names(.data), names(newdata)) | ||
|
||
display(glue::glue( | ||
"{.funname}: ", | ||
"reorganized ({format_list(oldcols)}) ", | ||
"into ({format_list(newcols)}) ", | ||
"[was {nrow(.data)}x{ncol(.data)}, ", | ||
"now {nrow(newdata)}x{ncol(newdata)}]" | ||
)) | ||
|
||
newdata | ||
} | ||
|
||
#' Wrapper around tidyr::spread | ||
#' that prints information about the operation | ||
#' | ||
#' @param .data a tbl; see \link[tidyr]{spread} | ||
#' @param ... see \link[tidyr]{spread} | ||
#' @return see \link[tidyr]{spread} | ||
#' @examples | ||
#' # create id | ||
#' mtcars$id <- 1:nrow(mtcars) | ||
#' gathered <- gather(mtcars, "col", "data", -id) | ||
#' #> gather: reorganized (mpg, cyl, disp, hp, drat, …) into (col, data) [was 32x12, now 352x3] | ||
#' spread(gathered, col, data) | ||
#' #> spread: reorganized (col, data) into (am, carb, cyl, disp, drat, …) [was 352x3, now 32x12] | ||
#' @import tidyr | ||
#' @export | ||
spread <- function(.data, ...) { | ||
log_spread(.data, .fun = tidyr::spread, .funname = "spread", ...) | ||
} | ||
|
||
log_spread <- function(.data, .fun, .funname, ...) { | ||
newdata <- .fun(.data, ...) | ||
|
||
if (!"data.frame" %in% class(.data) | !should_display()) { | ||
return(newdata) | ||
} | ||
|
||
newcols <- setdiff(names(newdata), names(.data)) | ||
oldcols <- setdiff(names(.data), names(newdata)) | ||
|
||
display(glue::glue( | ||
"{.funname}: ", | ||
"reorganized ({format_list(oldcols)}) ", | ||
"into ({format_list(newcols)}) ", | ||
"[was {nrow(.data)}x{ncol(.data)}, ", | ||
"now {nrow(newdata)}x{ncol(newdata)}]" | ||
)) | ||
|
||
newdata | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +0,0 @@ | ||
#' Wrapper around tidyr::spread | ||
#' that prints information about the operation | ||
#' | ||
#' @param .data a tbl; see \link[tidyr]{spread} | ||
#' @param ... see \link[tidyr]{spread} | ||
#' @return see \link[tidyr]{spread} | ||
#' @examples | ||
#' mtcars %>% | ||
#' mutate(id = 1:n()) %>% | ||
#' gather("col", "data", -id) %>% | ||
#' spread(col, data) | ||
#' #> spread: was 352 rows and 3 columns, now 32 rows and 12 columns; | ||
#' #> reorganized data from (col, data) into (am, carb, cyl, disp, drat, …) | ||
#' @import tidyr | ||
#' @export | ||
spread <- function(.data, ...) { | ||
log_spread(.data, .fun = tidyr::spread, .funname = "spread", ...) | ||
} | ||
|
||
log_spread <- function(.data, .fun, .funname, ...) { | ||
newdata <- .fun(.data, ...) | ||
|
||
if (!"data.frame" %in% class(.data) | !should_display()) { | ||
return(newdata) | ||
} | ||
|
||
newcols <- setdiff(names(newdata), names(.data)) | ||
oldcols <- setdiff(names(.data), names(newdata)) | ||
|
||
display(glue::glue( | ||
"{.funname}: ", | ||
"reorganized ({format_list(oldcols)}) ", | ||
"into ({format_list(newcols)}) ", | ||
"[was {nrow(.data)}x{ncol(.data)}, ", | ||
"now {nrow(newdata)}x{ncol(newdata)}]" | ||
)) | ||
|
||
newdata | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.