From 88bdb6c74335dc3a6abaa146e3c37304017caa89 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 21 Aug 2024 08:00:54 -0500 Subject: [PATCH] More polishing --- R/superseded-map-df.R | 15 ++++----------- man/map_dfr.Rd | 11 ++++------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/R/superseded-map-df.R b/R/superseded-map-df.R index 7d527a5e..8b9fb0d1 100644 --- a/R/superseded-map-df.R +++ b/R/superseded-map-df.R @@ -52,14 +52,12 @@ #' map_dfr(df, trimws) #' map_dfc(df, trimws) #' -#' # If you want to apply a function to each column of a data frame -#' # you might instead want to use modify: -#' modify(df, trimws) -#' -#' # list_rbind()/list_cbind() don't work here because they require -#' # data frame inputs +#' # 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){ @@ -78,11 +76,6 @@ #' 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()`")) diff --git a/man/map_dfr.Rd b/man/map_dfr.Rd index d92314de..f9c9dd43 100644 --- a/man/map_dfr.Rd +++ b/man/map_dfr.Rd @@ -82,14 +82,12 @@ df <- data.frame( map_dfr(df, trimws) map_dfc(df, trimws) -# If you want to apply a function to each column of a data frame -# you might instead want to use modify: -modify(df, trimws) - -# list_rbind()/list_cbind() don't work here because they require -# data frame inputs +# 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){ @@ -108,6 +106,5 @@ map2(arg1, arg2, ex_fun) |> list_rbind() map2_dfc(arg1, arg2, ex_fun) # now map2(arg1, arg2, ex_fun) |> list_cbind() - } \keyword{internal}