Skip to content

Commit

Permalink
Add example to map_dfr()/map_dfc() (#1140)
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

---------

Co-authored-by: Maike <[email protected]>
Co-authored-by: Hadley Wickham <[email protected]>
  • Loading branch information
3 people authored Aug 21, 2024
1 parent 48b2769 commit 5817933
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions R/superseded-map-df.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@
#' map(\(mod) as.data.frame(t(as.matrix(coef(mod))))) |>
#' list_rbind()
#'
#' # for certain pathological inputs `map_dfr()` and `map_dfc()` actually
#' # both combine the list by column
#' df <- data.frame(
#' x = c(" 13", " 15 "),
#' y = c(" 34", " 67 ")
#' )
#'
#' # Was:
#' map_dfr(df, trimws)
#' map_dfc(df, trimws)
#'
#' # But list_rbind()/list_cbind() fail because they require data frame inputs
#' try(map(df, trimws) |> list_rbind())
#'
#' # Instead, use modify() to apply a function to each column of a data frame
#' modify(df, trimws)
#'
#' # map2 ---------------------------------------------
#'
#' ex_fun <- function(arg1, arg2){
Expand Down
17 changes: 17 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 5817933

Please sign in to comment.