You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

pmap_df报bind_rows参数无名称错误,map_df能否替代plyr::ldply?

Solution to Argument 1 must have names Error & purrr vs. plyr::ldply

Great question—this exact issue used to drive me crazy too when I first switched from plyr to purrr. Let’s break down both the fix for your error and whether map_df can truly replace ldply.

Fixing the bind_rows Naming Error

The core problem here is that map_df/pmap_df rely on dplyr::bind_rows under the hood, which requires named inputs when passing vectors or non-dataframe list elements. But there’s a much cleaner workaround now, thanks to updates in the purrr package:

Use list_rbind() instead of *_df functions

Instead of using pmap_df() directly, run your pmap() call first, then pipe the result to purrr::list_rbind():

# Instead of this (which throws an error):
pmap_df(my_inputs, my_function)

# Do this instead:
pmap(my_inputs, my_function) %>% list_rbind()

list_rbind() is built to handle both named and unnamed lists gracefully—no need to tack on arbitrary names to your outputs just to satisfy bind_rows. If you want to add an ID column tracking which list element came from which input (like ldply’s .id argument), you can do that easily:

pmap(my_inputs, my_function) %>% list_rbind(.id = "source_id")

Temporary workaround (for older purrr versions)

If you’re stuck with an older purrr release that doesn’t have list_rbind(), you can manually convert each function output to a single-row dataframe inside your function. For example:

my_function <- function(a, b, c) {
  result <- c(a + b, c * 2)
  # Wrap the result in a dataframe to avoid naming issues
  tibble::tibble(col1 = result[1], col2 = result[2])
}
pmap_df(my_inputs, my_function)

This bypasses the error because you’re passing dataframes (which have explicit column names) to bind_rows.

Can map_df Series Fully Replace plyr::ldply?

Short answer: Yes, now that purrr has list_rbind() and list_cbind()—but early versions of purrr had gaps (like this naming requirement) that made ldply still useful for edge cases.

  • ldply was always flexible with unnamed lists—it would automatically coerce vectors into dataframe rows without fuss. Early map_df couldn’t match this because of bind_rows’ restrictions.
  • Modern purrr’s list_rbind() matches ldply’s flexibility, while integrating better with the tidyverse ecosystem (like working seamlessly with tibbles, supporting .id for source tracking, and handling more edge cases).

So unless you’re stuck on a very old purrr version, you don’t need to keep relying on ldply anymore—map() + list_rbind() is the clean, tidyverse-native replacement.

内容的提问来源于stack exchange,提问作者Novus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:11:43