diff --git a/R/superseded-map-df.R b/R/superseded-map-df.R index 065aa9c9..8b9fb0d1 100644 --- a/R/superseded-map-df.R +++ b/R/superseded-map-df.R @@ -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){ diff --git a/man/map_dfr.Rd b/man/map_dfr.Rd index 3274f223..f9c9dd43 100644 --- a/man/map_dfr.Rd +++ b/man/map_dfr.Rd @@ -71,6 +71,23 @@ mtcars |> 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){