【问题标题】:Reading the same file has different output in newer readr version在较新的阅读器版本中读取相同的文件具有不同的输出
【发布时间】:2021-10-25 16:36:21
【问题描述】:

读取文件不会在较新的 R 版本中返回相同的输出。

我有一个格式如下的文件:

      Symbol                 Location  N_ind_freqs
     A3GALT2      1:33772367-33786699            1
      ABCB10    1:229652329-229694442            1
       ABCD3      1:94883933-94984222            4
        ABL2    1:179068462-179198819            6

并习惯于使用该行阅读:

df_out <- read_delim("file.out", delim = " ", trim_ws = TRUE, col_types = "ccd")

您可以观察到第一列Symbol 中的空格,需要修剪。此代码 sn-p 按预期返回数据帧(3 列和 4 行)。

但是,readr::read_delim 在较新版本的 R (R 4.1.0) 中不会产生相同的输出 (df_out)。

您认为问题是什么?

【问题讨论】:

    标签: r tidyverse readr


    【解决方案1】:

    我怀疑问题不是由新版本的 R 引起的,而是由新版本的 readr 包引起的(假设你的函数 read_delim 来自 readr)。他们在 7 月中旬发布了 2.0.0 版本,并且有不少细节发生了变化。

    如果这确实是您的问题的根源,您应该能够通过使用 with_edition 函数返回到旧的行为。

    df_out <- with_edition(1, read_delim("file.out", delim = " ", trim_ws = TRUE, col_types = "ccd"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多