Skip to content

Instantly share code, notes, and snippets.

@avullo
Last active November 13, 2017 19:43
Show Gist options
  • Save avullo/124d87284b0c19a4ddd96282ac91871c to your computer and use it in GitHub Desktop.
Save avullo/124d87284b0c19a4ddd96282ac91871c to your computer and use it in GitHub Desktop.
R function to get the number of lines in a file
# 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