Skip to content

Commit 8e114ce

Browse files
committed
Return permissions as factor
ref #163
1 parent 91f7184 commit 8e114ce

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

R/constant.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@
6363
#' REDCapR::constant("access_yes") # Returns 1L
6464
#'
6565
#' REDCapR::constant(c("form_complete", "form_complete", "form_incomplete")) # Returns c(2L, 2L, 0L)
66-
#' REDCapR::constant(c("form_rights_no_access", "form_rights_readonly", "form_rights_readwrite")) # Returns c(0L, 1L, 2L)
66+
#' REDCapR::constant(c(
67+
#' "form_rights_no_access",
68+
#' "form_rights_readonly",
69+
#' "form_rights_readwrite"
70+
#' )) # Returns c(0L, 1L, 2L)
6771
#'
6872
#' \dontrun{
6973
#' # The following line returns an error:

R/redcap-users-export.R

+11-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,17 @@ redcap_users_export <- function( redcap_uri, token, verbose=TRUE, config_options
9999
# convert = FALSE
100100
# ) %>%
101101
dplyr::mutate(
102-
form_name = sub("^(\\w+):([0-2])$", "\\1", .data$forms),
103-
permission = sub("^(\\w+):([0-2])$", "\\2", .data$forms),
104-
permission = as.logical(as.integer(.data$permission))
102+
form_name = sub("^(\\w+):([0-2])$", "\\1", .data$forms),
103+
permission_id = sub("^(\\w+):([0-2])$", "\\2", .data$forms),
104+
permission_id = as.integer(.data$permission_id),
105+
permission = factor(
106+
.data$permission_id,
107+
# levels = c(0L , 2L , 1L ),
108+
levels = REDCapR::constant(c("form_rights_no_access", "form_rights_readonly", "form_rights_readwrite")) ,
109+
labels = c("No Access" , "Read Only" , "Read/Write"),
110+
ordered = TRUE
111+
)
112+
105113
) %>%
106114
dplyr::select_("-forms")
107115
},

man/constant.Rd

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-users-export.R

+8-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ test_that("with DAGs", {
4747
expected_data_user_form <- structure(
4848
list(username = c("dwells", "unittestphifree", "wbeasleya"
4949
), form_name = c("demographics", "demographics", "demographics"
50-
), permission = c(TRUE, TRUE, TRUE)), class = c("tbl_df", "tbl",
51-
"data.frame"), row.names = c(NA, -3L)
50+
), permission_id = c(1L, 1L, 1L), permission = structure(c(3L,
51+
3L, 3L), .Label = c("No Access", "Read Only", "Read/Write"), class = c("ordered",
52+
"factor"))), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
53+
-3L)
5254
)
5355

5456
expect_message(
@@ -96,8 +98,10 @@ test_that("with DAGs", {
9698
list(username = c("unittestphifree", "unittestphifree",
9799
"unittestphifree", "wbeasleya", "wbeasleya", "wbeasleya"), form_name = c("demographics",
98100
"health", "race_and_ethnicity", "demographics", "health", "race_and_ethnicity"
99-
), permission = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)), class = c("tbl_df",
100-
"tbl", "data.frame"), row.names = c(NA, -6L)
101+
), permission_id = c(1L, 1L, 1L, 1L, 1L, 1L), permission = structure(c(3L,
102+
3L, 3L, 3L, 3L, 3L), .Label = c("No Access", "Read Only", "Read/Write"
103+
), class = c("ordered", "factor"))), class = c("tbl_df", "tbl",
104+
"data.frame"), row.names = c(NA, -6L)
101105
)
102106

103107
expect_message(

0 commit comments

Comments
 (0)