问题描述
我有4K个* txt文件,其中的行数很重要,因为如果我的* txt文件为空,则需要计数为零,并且如果我有1个或更多行,则此信息也很有用。
但是read_lines
包中的函数readr
总是给我1行,因为我有一个空文件,在我的示例中:
library(tidyverse)
# *txt file with 1 line
myfile1<-read_lines("https://raw.githubusercontent.com/Leprechault/trash/main/sample_672.txt")
length(myfile1)
#[1] 1
myfile1
#[1] "0 0.229592 0.382716 0.214286 0.246914"
# *txt file with 0 line
myfile2<-read_lines("https://raw.githubusercontent.com/Leprechault/trash/main/sample_1206.txt")
length(myfile2)
#[1] 1
myfile2
#[1] ""
在myfile1中可以,因为我只有1行,但是在第二种情况下(myfile2)我没有一行,并且文件为空。拜托,我该如何解决这个问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)