Created
November 13, 2017 19:45
-
-
Save avullo/29a13b982ba9409175627b30d92a6486 to your computer and use it in GitHub Desktop.
R function to get the number of empty 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
# 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