read_delim 报错解决 “Warning: 754 parsing failures.”

本文介绍了解决使用read_delim函数读取文件时出现的解析错误问题,特别是当第三列被误判为logical类型时的解决方案。通过调整guess_max参数的值,确保了数据的正确读取。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


报错信息如下:
Parsed with column specification:
cols(
  ECs = col_character(),
  Combine_IDs = col_character(),
  compoundIDs = col_logical()
)
Warning: 754 parsing failures.
 row         col           expected                                                                                                                                                                                                   actual                                                                                                                                                                                   file
3257 compoundIDs 1/0/T/F/TRUE/FALSE CID:942,                                                                      '3241_healthy_microbiome_compoundsID.txt'
3258 compoundIDs 1/0/T/F/TRUE/FALSE CID [... truncated]


根据信息定位到是read_delim读入报的错 

individuals_microbiome_combined_enzyme <- read_delim( "3214_healthy_microbiome_compoundsID.txt", sep = ""), 
                                                       delim = "\t") %>%

separate_rows(., compoundIDs, sep = ",")

根据报错信息,read_delim把我的文件第三列判断为logical数据,这才导致后面读入报错。

因为read_delim是根据文件前几列来猜测数据结构,因为我有些行是空值,而有数值的又在后面,所以只需要把guess的行数提高些就可以了,这样第三列就会读入character了

individuals_microbiome_combined_enzyme <- read_delim( "3214_healthy_microbiome_compoundsID.txt", sep = ""), 
                                                       delim = "\t", guess_max = 50000) %>%

separate_rows(., compoundIDs, sep = ",")

输出信息

Parsed with column specification:
cols(
  ECs = col_character(),
  Combine_IDs = col_character(),
  compoundIDs = col_character()

 

参考Ref:

https://cran.r-project.org/web/packages/readr/vignettes/readr.html

 

 

意外实参可能的被调用方:read_csv(filepath_or_buffer: str | PathLike[str] | ReadCsvBuffer[bytes] | ReadCsvBuffer[str], *, sep: str | None | _NoDefault = ..., delimiter: str | None | _NoDefault = ..., header: int | Sequence[int] | None | Literal["infer"] = ..., names: Sequence[Hashable] | None | _NoDefault = ..., index_col: Hashable | Sequence[Hashable] | Literal[False] | None = ..., usecols: SequenceNotStr[Hashable] | range | ExtensionArray | ndarray | Index | Series | (HashableT) -> bool | None = ..., dtype: ExtensionDtype | str | dtype | Type[str] | Type[complex] | Type[bool] | Type[object] | dict[Hashable, ExtensionDtype | str | dtype | Type[str] | Type[complex] | Type[bool] | Type[object]] | None = ..., engine: Literal["c", "python", "pyarrow", "python-fwf"] | None = ..., converters: Mapping[Hashable, (...) -> Any] | None = ..., true_values: list | None = ..., false_values: list | None = ..., skipinitialspace: bool = ..., skiprows: list[int] | int | (Hashable) -> bool | None = ..., skipfooter: int = ..., nrows: int | None = ..., na_values: Hashable = ..., na_filter: bool = ..., verbose: bool | _NoDefault = ..., skip_blank_lines: bool = ..., parse_dates: bool | Sequence[Hashable] | None = ..., infer_datetime_format: bool | _NoDefault = ..., keep_date_col: bool | _NoDefault = ..., date_parser: (...) -> Any | _NoDefault = ..., date_format: str | dict[Hashable, str] | None = ..., dayfirst: bool = ..., cache_dates: bool = ..., iterator: Literal[True], chunksize: int | None = ..., compression: Literal["infer", "gzip", "bz2", "zip", "xz", "zstd", "tar"] | dict[str, Any] | None = ..., thousands: str | None = ..., decimal: str = ..., lineterminator: str | None = ..., quotechar: str = ..., quoting: int = ..., doublequote: bool = ..., escapechar: str | None = ..., comment: str | None = ..., encoding: str | None = ..., encoding_errors: str | None = ..., dialect: str | Dialect | Dialect | None = ..., on_bad_lines=..., delim_whitespace: bool | _NoDefault = ..., low_memory: bool = ..., mem
03-17
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值