Skip to content

Instantly share code, notes, and snippets.

@avullo
Created November 13, 2017 19:45
Show Gist options
  • Save avullo/29a13b982ba9409175627b30d92a6486 to your computer and use it in GitHub Desktop.
Save avullo/29a13b982ba9409175627b30d92a6486 to your computer and use it in GitHub Desktop.
R function to get the number of empty lines in a file
# count empty lines in a file
numberOfEmptyLines <- function(fname) {
if(!file.exists(fname)) {
stop(paste("Cannot read file ", fname, sep = " "))
}
as.integer(strsplit(try(system(paste("grep -cP '^$'", fname, sep = " "), intern = TRUE)), " +")[[1]][1])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment