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

导入含超长列名CSV遇cli::ansi_strwrap内部错误的解决求助

导入超长列名CSV文件时触发cli::ansi_strwrap内部错误

问题重现代码

使用readr包导入CSV时执行以下代码:

library(readr)

surveyData_twoConditions <- read_csv("Raw Data/Survey Data/fileName_extremelyLongColumnNames.csv", 
                           col_types = cols(`Start Date` = col_character()))

疑似触发问题的列名

怀疑问题由某超长列名引发,该列名内容如下:

What should be the output of the following code below?

 
public class Test {
    public static void main(String args[]) {   
             System.out.println("Hello World")
    } 
}

错误信息

导入时出现错误:

• ansi_strwrap(text, exdent = exdent, width = app$get_width(extra = padding)):

! Internal error in cli::ansi_strwrap()
Type .Last.error to see the more details.

错误回溯信息:

Backtrace:
 1. readr::read_csv("Raw Data/Survey Data/fileName_extremelyLongColumnNames.csv", …
 2. vroom::vroom(file, delim = ",", col_names = col_names, col_types = col_types, …
 3. vroom:::vroom_(file, delim = delim %||% col_types$delim, col_names = col_names, …
 4. (function (spec, num_cols, col_names, col_select, name_repair) …
 5. vctrs::vec_as_names(col_names, repair = name_repair)
 6. vctrs:::describe_repair(c("Start Date", "End Date", "Response Type", …
 7. rlang::names_inform_repair(orig_names, names)
 8. rlang::inform(message = message, class = "rlib_message_name_repair")
 9. base::withRestarts(muffleMessage = function() NULL, { …
10. base::withOneRestart(expr, restarts[[1L]])
11. base::doWithOneRestart(return(expr), restart)
12. base::signalCondition(cnd)
13. base::conditionMessage(cond)
14. rlang:::conditionMessage.rlang_message(cond)
15. rlang::cnd_message(c)
16. rlang:::cnd_message_format(cnd, ...)
17. local cli_format(glue_escape(lines))
18. rlang:::.rlang_cli_format(x, cli::format_message)
19. cli::cli_format(x, .envir = emptyenv())
20. cli::cli_fmt((function() { …
21. cli:::cli__fmt(rec, collapse, strip_newline)
22. base::do.call(app[[msg$type]], msg$args)
23. (function (text, id = NULL, class = NULL) …
24. cli:::clii_bullets(app, text, id, class)
25. base::lapply(seq_along(text), function(i) { …
26. local FUN(X[[i]], ...)
27. app$text(text[[i]])
28. cli:::clii_text(app, text)
29. app$xtext(text)
30. cli:::clii__xtext(app, text, .list = .list, indent = indent, padding = padding)
31. cli::ansi_strwrap(text, exdent = exdent, width = app$get_width(extra = padding))
32. cli:::throw(cli_error("Internal error in {.fun cli::ansi_strwrap}"))

环境信息

出现问题的个人PC环境:

> packageVersion("readr")
[1] ‘2.1.4’

> R.version
               _                                
platform       x86_64-w64-mingw32               
arch           x86_64                            
os             mingw32                           
crt            ucrt                              
system         x86_64, mingw32                   
status                                           
major          4                                
minor          2.1                               
year           2022                              
month          06                                
day            23                                
svn rev        82513                             
language       R                                
version.string R version 4.2.1 (2022-06-23 ucrt)
nickname       Funny-Looking Kid  

现状与需求

  • 缩短列名可解决问题,但已基于原超长列名设计完整工作流,不想修改文件列名
  • 该错误仅在个人PC出现,办公室PC无此问题
  • 已尝试重装readr和tidyverse包,问题仍存在

解决方案

方案1:禁用列名修复提示

在read_csv中指定name_repair = "none",跳过自动列名修复及相关提示,避免触发cli的格式化错误:

library(readr)

surveyData_twoConditions <- read_csv(
  "Raw Data/Survey Data/fileName_extremelyLongColumnNames.csv", 
  col_types = cols(`Start Date` = col_character()),
  name_repair = "none"
)

注:此方法会保留原始列名,若存在重复列名可能引发后续问题,需确保列名本身无重复。

方案2:临时抑制列名修复信息

通过rlang::with_options临时关闭列名修复的信息提示,既保留自动修复逻辑,又避免触发错误:

library(readr)
library(rlang)

with_options(
  c(rlib_message_name_repair = "quiet"),
  surveyData_twoConditions <- read_csv(
    "Raw Data/Survey Data/fileName_extremelyLongColumnNames.csv", 
    col_types = cols(`Start Date` = col_character())
  )
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 15:35:43