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

使用R的map命令出现‘Corrupt x: no names’错误的排查与解决

Diagnosis & Fix for "Corrupt x: no names" Error

The error you're encountering stems from a function name conflict: you loaded the maps package after tidyverse, which means the map() function from maps (used for drawing geographic maps) is masking the map() function from purrr (used for applying functions to lists). When you run map(by_country$data, country_model), R tries to use maps::map() instead of purrr::map()—which expects completely different inputs, hence the confusing error message.


Fix 1: Explicitly use purrr::map()

The simplest solution is to specify you want the list-processing map() from the purrr package:

models <- purrr::map(by_country$data, country_model)

Fix 2: Adjust library loading order

If you load tidyverse after maps, purrr::map() will take precedence over maps::map(). Rearrange your library calls like this:

# Load non-tidyverse packages first
library(maps)
library(mapdata)
library(viridis)
library(lubridate)
library(stringr)
library(modelr)

# Load tidyverse last to ensure purrr's functions are active
library(tidyverse)

Fix 3: Detach maps temporarily

If you don't need the maps package for this part of your workflow, unload it before using map():

detach("package:maps", unload = TRUE)
models <- map(by_country$data, country_model)

Bonus: Keep models in your data frame

Instead of creating a separate models object, add the models directly to your by_country data frame using mutate()—this avoids function masking issues entirely:

by_country <- by_country %>%
  mutate(model = purrr::map(data, country_model))

Preventing this in the future

To check which map() function is active, run map::map. If it returns function (.x, .f, ...) purrr::map(.x, .f, ...), purrr::map() is in use. If it returns a function related to geographic maps, maps::map() is masking it.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:23:41