Get the number of lines in a text file using R

后端 未结 5 1263
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 10:51

Is there a way to get the number of lines in a file without importing it?

So far this is what I am doing

myfiles <- list.files(pattern=\"*.dat\")
         


        
5条回答
  •  执念已碎
    2020-12-05 11:20

    Maybe I am missing something but usually I do it using length on top of ReadLines:

    con <- file("some_file.format") 
    length(readLines(con))
    

    This at least has worked with many cases I had. I think it's kinda fast and it does only create a connection to the file without importing it.

提交回复
热议问题