Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile and report on all errors in getSiteId() #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions FourCePhase2.1Data/R/inputFileFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,31 @@ getSiteId <- function() {
)

siteId = NA

# Compile errors into a list.
errors = list()

## for each file pattern we are supposed to match
for (currFNamePattern in fNamePatterns) {

ix = grep(pattern=currFNamePattern, x=fNames)

## if no match, stop
# Note if we find no match.
if (length(ix) == 0) {
stop("No match found for file name pattern: ", currFNamePattern)
errors[[currFNamePattern]] =
paste("No match found for file name pattern:", currFNamePattern)
next
}

## if multiple matches, stop
# Note if we find multiple matches
if (length(ix) > 1) {
stop("Multiple matches found for file name pattern: ", currFNamePattern, ": ", paste(fNames[ix], collapse=", "))
errors[[currFNamePattern]] =
paste("Multiple matches found for file name pattern: ",
currFNamePattern, ": ", paste(fNames[ix], collapse=", "))
next
}

## so we have exactly one match, make sure all files are named for the same site ID
# So we have exactly one match, make sure all files are named for the same site ID
prefixSuffix = strsplit(x=currFNamePattern, split=".+\\", fixed=TRUE)[[1]]
currSiteId =
gsub(
Expand All @@ -88,9 +96,17 @@ getSiteId <- function() {
}

if (siteId != currSiteId) {
stop("Files for multiple sites found in the input data directory: ", siteId, ", ", currSiteId)
errors[[currFNamePattern]] =
paste0("Files for multiple sites found in the input data directory: ",
siteId, ", ", currSiteId)
}
}


if (length(errors) > 0) {
cat("Error(s) found in getSiteId():\n")
cat(" *", paste(unname(errors), collapse = "\n * "), "\n")
stop("Could not complete getSiteId(). See https://github.com/covidclinical/Phase2.1DataRPackage for help.")
}

return(siteId)
}