-
Notifications
You must be signed in to change notification settings - Fork 1
/
NAtest.R
29 lines (25 loc) · 917 Bytes
/
NAtest.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
NAtest <- function(file, ..., sep=",", header=TRUE, na.rm=TRUE, rowstoname=TRUE){
#Collects any number in filename longer than 4 digits
filenumber <- as.numeric(regmatches(file, regexpr("[[:digit:]]{4,}", file)))
test <- read.table(file, sep=sep, header=header, ...)
orig_rows <- nrow(test)
if(na.rm){
test <- na.exclude(test)
if(orig_rows == nrow(test)){
message("No NAs present: All is well")
} else {
warning("NAs present! ABORT ABORT")
}
}
if(rowstoname){
if(nrow(test) != filenumber){
warning(paste0("Filename suggests ", filenumber, " rows, actually has ", nrow(test), " rows!"))
} else {
message(paste0("File has same number of rows as it suggests: ", filenumber))
}
}
}
return(test)
}
# Line 3 if this goes astray: #test<-read.table("CarbonK1_nogap_top_K.txt",sep=",")
# NAtest("CarbonK1_nogap_top_K.txt")