r - 最终记录中缺少 CRLF,导致读取数据集出现问题
问题描述
我有两个数据集,其中包含最后一行缺少 CRLF 的数据行。我必须将其添加到文件中才能读入它们。有没有一种方法可以在不修改这些文件的情况下读入?
最终记录之一如下所示:
surface NewYork Ave. 1259 1290 no final carriage return
at end of record
警告信息:
In readLines(file, n = thisblock) : incomplete final line found on
roadways.dat'
谢谢。毫米
解决方案
我设法重现您的问题的唯一方法是使用 win unicode 文件encoding = "UCS-2LE"
。解决问题的几种方法,如果它产生所需的输出,则警告您对其进行测试。在大多数情况下,这是一个警告,您可以使用可用的开关来抑制它。
# set the warning FALSE (Assuming it is just a warning with no effect)
data <- readLines(con <- file("your_file", encoding = "UCS-2LE"), warn = FALSE, n=-1)
# Or see if other alternative encoding can solve your problem
A <- readLines(con <- file("your_file", encoding = "UTF-8"), n=-1)
推荐阅读
- mysql - MYSQL 自动删除超过 7 天的行
- c# - 无法设置“会话”变量 MVC 5
- sql - SQL Server 的命令行执行未找到 CMD 变量
- python-3.x - 从一个文件导入到另一个文件时遇到问题
- ruby-on-rails - 调整大小不适用于 Shrine 和 ImageProcessor / MiniMagick - Rails 5.2
- flutter - 颤振蜂巢箱不可听
- python - 断言多个方法被调用,只有构造函数有效
- python - 运行 jupyter notebook 文件夹中的脚本 (.ipynb)
- google-apps-script - TypeError:无法读取未定义的属性“响应”(第 8 行,文件“代码”)
- java - 如何在 android java 中使用 Canvas onDraw() 绘制导航路径