Skip to content

Commit

Permalink
Add example to map_dfr()/map_dfc()
Browse files Browse the repository at this point in the history
Example to demonstrate an edge case, where map_dfr() works, but can not be replaced by list_rbind(). Fixes #1074
  • Loading branch information
Maike committed Aug 15, 2024
1 parent 49bb36b commit 05ddff8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
31 changes: 31 additions & 0 deletions R/superseded-map-df.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,32 @@
#' map(\(mod) as.data.frame(t(as.matrix(coef(mod))))) |>
#' list_rbind()
#'
#' # map: combining vectors ---------------------------
#' DF <- structure(
#' list(
#' `Column A` = c(" 13", " 15 "),
#' `Column B` = c(" 34", " 67 ")
#' ),
#' class = c("data.frame"),
#' row.names = c(NA, -2L)
#' )
#'
#' # Was:
#' # map_dfr() and map_dfc() actually both combine the list by column
#' map_dfr(DF, trimws)
#' map_dfc(DF, trimws)
#'
#' # Now:
#' # to combine a list of vectors use as_tibble()
#' map(DF, trimws) |> tibble::as_tibble()
#'
#' # list_rbind()/list_cbind() require list of data.frames or NULL to work and
#' # will throw an error
#' \dontrun{
#' map(DF, trimws) |> list_rbind()
#' map(DF, trimws) |> list_cbind()
#' }
#'
#' # map2 ---------------------------------------------
#'
#' ex_fun <- function(arg1, arg2){
Expand All @@ -59,6 +85,11 @@
#' map2_dfc(arg1, arg2, ex_fun)
#' # now
#' map2(arg1, arg2, ex_fun) |> list_cbind()
#'




map_dfr <- function(.x, .f, ..., .id = NULL) {
# in 1.0.0
lifecycle::signal_stage("superseded", "map_dfr()", I("`map()` + `list_rbind()`"))
Expand Down
27 changes: 27 additions & 0 deletions man/map_dfr.Rd

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

0 comments on commit 05ddff8

Please sign in to comment.