Last active
November 13, 2017 19:43
-
-
Save avullo/124d87284b0c19a4ddd96282ac91871c to your computer and use it in GitHub Desktop.
R function to get the number of lines in a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the number of lines in a file | |
numberOfLines <- function(fname) { | |
if(!file.exists(fname)) { | |
stop(paste("Cannot read file ", fname, sep = " ")) | |
} | |
as.integer(strsplit(try(system(paste("wc", fname, sep = " "), intern = TRUE)), " +")[[1]][2]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment