I've written the if statement below in R. It works fine, but there's a pesky warning message which I 1) don't completely understand and 2) would like to not get. :-)
With respect to 1): What does it mean
"Warning message: closing unused connection 3"
And what does the number (3) mean in this context? Googling found me some pointers (How to fix error "closing unused connection" and Warning: closing unused connection n), which do not seem to work, but I know: it's probably me. What am I doing wrong? Below's my code.
Thanks!
Sander
filetype = summary(file(opt$datagwas))$class
if(filetype == "gzfile"){
cat("\n* The file appears to be gzipped, checking delimiter now...")
TESTDELIMITER = readLines(opt$datagwas, n = 1)
cat("\n* Data header looks like this:\n")
print(TESTDELIMITER)
if(grepl(",", TESTDELIMITER) == TRUE){
cat("\n* Data is comma-seperated, loading...\n")
GWASDATA_RAW = fread(paste0("zcat < ",opt$datagwas),
header = TRUE, sep = ",", dec = ".",
na.strings = c("", "NA", "na", "Na", "NaN",
"Nan", ".","N/A","n/a", "N/a"),
blank.lines.skip = TRUE)
} else {
cat ("\n\n*** ERROR *** Something is rotten in the City of Gotham. The GWAS data is neither comma, tab, space, nor semicolon delimited. Double back, please.\n\n", file=stderr()) # print error messages to stder
}
} else if(filetype != "gzfile") {
cat("\n* The file appears not to be gezipped, checking delimiter now...")
TESTDELIMITER = readLines(opt$datagwas, n = 1)
cat("\n* Data header looks like this:\n")
print(TESTDELIMITER)
if(grepl(",", TESTDELIMITER) == TRUE){
cat("\n* Data is comma-seperated, loading...\n")
GWASDATA_RAW = fread(opt$datagwas,
header = TRUE, sep = ",",dec = ".",
na.strings = c("", "NA", "na", "Na","NaN",
"Nan", ".","N/A","n/a","N/a"),
blank.lines.skip = TRUE)
} else {
cat ("\n\n*** ERROR *** Something is rotten in the City of Gotham. The GWAS data is neither comma, tab, space, nor semicolon delimited. Double back, please.\n\n", file=stderr()) # print error messages to stder
}
} else {
cat ("\n\n*** ERROR *** Something is rotten in the City of Gotham. We can't determine the file type of the GWAS data. Double back, please.\n\n", file=stderr()) # print error messages to stder
}
closeAllConnections()