Skip to content

Commit

Permalink
Return permissions as factor
Browse files Browse the repository at this point in the history
ref #163
  • Loading branch information
wibeasley committed Sep 17, 2018
1 parent 91f7184 commit 8e114ce
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
6 changes: 5 additions & 1 deletion R/constant.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@
#' REDCapR::constant("access_yes") # Returns 1L
#'
#' REDCapR::constant(c("form_complete", "form_complete", "form_incomplete")) # Returns c(2L, 2L, 0L)
#' REDCapR::constant(c("form_rights_no_access", "form_rights_readonly", "form_rights_readwrite")) # Returns c(0L, 1L, 2L)
#' REDCapR::constant(c(
#' "form_rights_no_access",
#' "form_rights_readonly",
#' "form_rights_readwrite"
#' )) # Returns c(0L, 1L, 2L)
#'
#' \dontrun{
#' # The following line returns an error:
Expand Down
14 changes: 11 additions & 3 deletions R/redcap-users-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,17 @@ redcap_users_export <- function( redcap_uri, token, verbose=TRUE, config_options
# convert = FALSE
# ) %>%
dplyr::mutate(
form_name = sub("^(\\w+):([0-2])$", "\\1", .data$forms),
permission = sub("^(\\w+):([0-2])$", "\\2", .data$forms),
permission = as.logical(as.integer(.data$permission))
form_name = sub("^(\\w+):([0-2])$", "\\1", .data$forms),
permission_id = sub("^(\\w+):([0-2])$", "\\2", .data$forms),
permission_id = as.integer(.data$permission_id),
permission = factor(
.data$permission_id,
# levels = c(0L , 2L , 1L ),
levels = REDCapR::constant(c("form_rights_no_access", "form_rights_readonly", "form_rights_readwrite")) ,
labels = c("No Access" , "Read Only" , "Read/Write"),
ordered = TRUE
)

) %>%
dplyr::select_("-forms")
},
Expand Down
6 changes: 5 additions & 1 deletion man/constant.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions tests/testthat/test-users-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ test_that("with DAGs", {
expected_data_user_form <- structure(
list(username = c("dwells", "unittestphifree", "wbeasleya"
), form_name = c("demographics", "demographics", "demographics"
), permission = c(TRUE, TRUE, TRUE)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -3L)
), permission_id = c(1L, 1L, 1L), permission = structure(c(3L,
3L, 3L), .Label = c("No Access", "Read Only", "Read/Write"), class = c("ordered",
"factor"))), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-3L)
)

expect_message(
Expand Down Expand Up @@ -96,8 +98,10 @@ test_that("with DAGs", {
list(username = c("unittestphifree", "unittestphifree",
"unittestphifree", "wbeasleya", "wbeasleya", "wbeasleya"), form_name = c("demographics",
"health", "race_and_ethnicity", "demographics", "health", "race_and_ethnicity"
), permission = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -6L)
), permission_id = c(1L, 1L, 1L, 1L, 1L, 1L), permission = structure(c(3L,
3L, 3L, 3L, 3L, 3L), .Label = c("No Access", "Read Only", "Read/Write"
), class = c("ordered", "factor"))), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -6L)
)

expect_message(
Expand Down

0 comments on commit 8e114ce

Please sign in to comment.