Skip to content

Commit

Permalink
remove empty pids
Browse files Browse the repository at this point in the history
ref #539
  • Loading branch information
wibeasley committed Oct 13, 2024
1 parent f6d7126 commit 3158d03
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions R/retrieve-credential.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,22 @@ retrieve_credential_local <- function(
comment = readr::col_character()
)

ds_credentials <- readr::read_csv(
d_credentials <- readr::read_csv(
file = path_credential,
col_types = col_types,
comment = "#",
show_col_types = FALSE
)

# Check that it's a data.frame with valid variable names
if (!inherits(ds_credentials, "data.frame")) {
if (!inherits(d_credentials, "data.frame")) {
stop(
"The credentials file was not correctly transformed into a ",
"[base::data.frame()]. Make sure it's a well-formed CSV."
)
} else if (
!identical(
colnames(ds_credentials),
colnames(d_credentials),
c("redcap_uri", "username", "project_id", "token", "comment"))
) {
stop(
Expand All @@ -177,30 +177,31 @@ retrieve_credential_local <- function(
}

# Select only the records with a matching project id.
ds_credential <- ds_credentials[ds_credentials$project_id == project_id, ]
d_credentials <- d_credentials[!is.na(d_credentials$project_id), ]
d_credential <- d_credentials[d_credentials$project_id == project_id, ]

# If specified, select only the records with a matching username.
if (!is.na(username)) {
ds_credential <- ds_credentials[ds_credentials$username == username, ]
d_credential <- d_credentials[d_credentials$username == username, ]
}

# Check that one and only one record matches the project id.
if (nrow(ds_credential) == 0L) {
if (nrow(d_credential) == 0L) {
stop(
"The project_id was not found in the csv credential file."
)
} else if (1L < nrow(ds_credential)) {
} else if (1L < nrow(d_credential)) {
stop(
"More than one matching project_id was found in the csv credential ",
"file. There should be only one."
)
} else {
credential <- list(
redcap_uri = ds_credential$redcap_uri[1],
username = ds_credential$username[1],
project_id = ds_credential$project_id[1],
token = ds_credential$token[1],
comment = ds_credential$comment[1]
redcap_uri = d_credential$redcap_uri[1],
username = d_credential$username[1],
project_id = d_credential$project_id[1],
token = d_credential$token[1],
comment = d_credential$comment[1]
)
}

Expand Down

0 comments on commit 3158d03

Please sign in to comment.