OuhscBbmc / REDCapR
Showing 28 of 76 files from the diff.
Other files ignored by Codecov
.lintr is new.
.Rbuildignore has changed.
inst/WORDLIST has changed.
man/kernel_api.Rd has changed.
utility/refresh.R has changed.
DESCRIPTION has changed.
tests/spelling.R has changed.
NEWS.md has changed.

@@ -4,8 +4,11 @@
Loading
4 4
#'
5 5
#' @param file_name The name of the relative or full file to be uploaded into
6 6
#' the REDCap project.  Required.
7 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
8 -
#' project.  Required.
7 +
#' @param redcap_uri The
8 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
9 +
#' of the REDCap server
10 +
#' typically formatted as "https://server.org/apps/redcap/api/".
11 +
#' Required.
9 12
#' @param token The user-specific string that serves as the password for a
10 13
#' project.  Required.
11 14
#' @param record The record ID where the file is to be imported.  Required

@@ -2,8 +2,11 @@
Loading
2 2
#'
3 3
#' @description This function uses REDCap's API to query its version.
4 4
#'
5 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
6 -
#' project.  Required.
5 +
#' @param redcap_uri The
6 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
7 +
#' of the REDCap server
8 +
#' typically formatted as "https://server.org/apps/redcap/api/".
9 +
#' Required.
7 10
#' @param token The user-specific string that serves as the password for
8 11
#' a project.  Required.
9 12
#' @param verbose A boolean value indicating if `message`s should be printed
@@ -59,7 +62,7 @@
Loading
59 62
      #   under the control of the caller.
60 63
    )
61 64
62 -
    if (exists("version") & inherits(version, "package_version")) {
65 +
    if (exists("version") && inherits(version, "package_version")) {
63 66
      outcome_message <- sprintf(
64 67
        "The REDCap version was successfully determined in %0.1f seconds. The http status code was %i.  Is is %s.",
65 68
        kernel$elapsed_seconds,

@@ -1,4 +1,4 @@
Loading
1 -
retrieve_credential_testing <- function (project_id = 153L, username = NA_character_) {
1 +
retrieve_credential_testing <- function(project_id = 153L, username = NA_character_) {
2 2
  checkmate::assert_integer(project_id, lower = 1, len = 1, any.missing = FALSE)
3 3
   REDCapR::retrieve_credential_local(
4 4
    path_credential = system.file("misc/example.credentials", package="REDCapR"),
@@ -8,7 +8,7 @@
Loading
8 8
}
9 9
10 10
# This function isn't used during testing itself.  Just to create the expected file.
11 -
save_expected <- function (o, path) {
11 +
save_expected <- function(o, path) {
12 12
  # nocov start
13 13
  path <- file.path("inst", path)
14 14
  if (!dir.exists(dirname(path))) dir.create(dirname(path), recursive = FALSE)
@@ -17,7 +17,7 @@
Loading
17 17
  # nocov end
18 18
}
19 19
20 -
retrieve_expected <- function (path) {
20 +
retrieve_expected <- function(path) {
21 21
  full_path   <- system.file(path, package = "REDCapR")
22 22
  if (!file.exists(full_path))
23 23
    stop("The expected file `", full_path, "` was not found.")  # nocov

@@ -59,11 +59,13 @@
Loading
59 59
    )
60 60
  ds_batch$stop_index  <-
61 61
    base::mapply(
62 -
      function(i) base::ifelse(
63 -
        i < length(start_index),
64 -
        start_index[i + 1L] - 1L,
65 -
        row_count
66 -
      ),
62 +
      function(i) {
63 +
        base::ifelse(
64 +
          i < length(start_index),
65 +
          start_index[i + 1L] - 1L,
66 +
          row_count
67 +
        )
68 +
      },
67 69
      ds_batch$id
68 70
    )
69 71

@@ -6,8 +6,11 @@
Loading
6 6
#' (Copied from "Export Instrument-Event Mappings" method of
7 7
#' REDCap API documentation, v.10.5.1)
8 8
#'
9 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
10 -
#' project.  Required.
9 +
#' @param redcap_uri The
10 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
11 +
#' of the REDCap server
12 +
#' typically formatted as "https://server.org/apps/redcap/api/".
13 +
#' Required.
11 14
#' @param token The user-specific string that serves as the password for a
12 15
#' project.  Required.
13 16
#' @param arms A character string of arms to retrieve.  (Default: '1')
@@ -75,7 +78,7 @@
Loading
75 78
    token     = token,
76 79
    content   = "formEventMapping",
77 80
    format    = "csv",
78 -
    'arms[0]' = collapse_vector(arms, NULL)
81 +
    "arms[0]" = collapse_vector(arms, NULL)
79 82
  )
80 83
81 84
  col_types <- readr::cols(
@@ -101,7 +104,7 @@
Loading
101 104
      #    it's under the control of the caller.
102 105
    )
103 106
104 -
    if (exists("ds") & inherits(ds, "data.frame")) {
107 +
    if (exists("ds") && inherits(ds, "data.frame")) {
105 108
      outcome_message <- sprintf(
106 109
        "%s event instrument metadata records were read from REDCap in %0.1f seconds.  The http status code was %i.",
107 110
        format(nrow(ds), big.mark = ",", scientific = FALSE, trim = TRUE),
@@ -137,7 +140,7 @@
Loading
137 140
    }
138 141
  }
139 142
140 -
  if( verbose )
143 +
  if (verbose)
141 144
    message(outcome_message)
142 145
143 146
  list(

@@ -15,8 +15,11 @@
Loading
15 15
#' @param continue_on_error If an error occurs while reading, should records
16 16
#' in subsequent batches be attempted.  The default is `FALSE`, which prevents
17 17
#' subsequent batches from running.  Required.
18 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
19 -
#' project.  Required.
18 +
#' @param redcap_uri The
19 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
20 +
#' of the REDCap server
21 +
#' typically formatted as "https://server.org/apps/redcap/api/".
22 +
#' Required.
20 23
#' @param token The user-specific string that serves as the password for a
21 24
#' project.  Required.
22 25
#' @param records An array, where each element corresponds to the ID of a
@@ -150,9 +153,11 @@
Loading
150 153
#' \dontrun{
151 154
#' uri     <- "https://bbmc.ouhsc.edu/redcap/api/"
152 155
#' token   <- "9A81268476645C4E5F03428B8AC3AA7B"
156 +
#'
157 +
#' # Return the entire dataset
153 158
#' REDCapR::redcap_read(batch_size=2, redcap_uri=uri, token=token)$data
154 159
#'
155 -
#' # Specify the column types.
160 +
#' # Return a subset of columns while also specifying the column types.
156 161
#' col_types <- readr::cols(
157 162
#'   record_id  = readr::col_integer(),
158 163
#'   race___1   = readr::col_logical(),
@@ -303,7 +308,7 @@
Loading
303 308
  # Continue as intended if the initial query succeeded. --------------------
304 309
  unique_ids <- sort(unique(initial_call$data[[id_position]]))
305 310
306 -
  if (0L < length(unique_ids) & all(nchar(unique_ids)==32L))
311 +
  if (0L < length(unique_ids) && all(nchar(unique_ids)==32L))
307 312
    warn_hash_record_id()  # nocov
308 313
309 314
  ds_glossary            <- REDCapR::create_batch_glossary(row_count=length(unique_ids), batch_size=batch_size)

@@ -9,8 +9,11 @@
Loading
9 9
#' directory. Optional
10 10
#' @param overwrite Boolean value indicating if existing files should be
11 11
#' overwritten. Optional
12 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
13 -
#' project.  Required.
12 +
#' @param redcap_uri The
13 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
14 +
#' of the REDCap server
15 +
#' typically formatted as "https://server.org/apps/redcap/api/".
16 +
#' Required.
14 17
#' @param token The user-specific string that serves as the password for a
15 18
#' project.  Required.
16 19
#' @param record The record ID where the file is to be imported. Required
@@ -156,7 +159,7 @@
Loading
156 159
  if (kernel$success) {
157 160
    result_header <- kernel$result_headers$`content-type`
158 161
159 -
    if (missing(file_name) | is.null(file_name)) {
162 +
    if (missing(file_name) || is.null(file_name)) {
160 163
      # process the content-type to get the file name
161 164
      regex_matches <- regmatches(
162 165
        kernel$result_headers,
@@ -170,7 +173,7 @@
Loading
170 173
      )
171 174
    }
172 175
173 -
    file_path <- if (missing(directory) & is.null(directory)) {
176 +
    file_path <- if (missing(directory) && is.null(directory)) {
174 177
      file_name #Use relative path.
175 178
    } else {
176 179
      file.path(directory, file_name) #Qualify the file with its full path.
@@ -179,7 +182,7 @@
Loading
179 182
    if (verbose)
180 183
      message("Preparing to download the file `", file_path, "`.")
181 184
182 -
    if (!overwrite & file.exists(file_path)) {
185 +
    if (!overwrite && file.exists(file_path)) {
183 186
      stop(
184 187
        "The operation was halted because the file `",
185 188
        file_path,

@@ -3,8 +3,11 @@
Loading
3 3
#' @description This function is used by other functions to read and write
4 4
#' values.
5 5
#'
6 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
7 -
#' project.  Required.
6 +
#' @param redcap_uri The
7 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
8 +
#' of the REDCap server
9 +
#' typically formatted as "https://server.org/apps/redcap/api/".
10 +
#' Required.
8 11
#' @param post_body List of contents expected by the REDCap API.  Required.
9 12
#' @param config_options  A list of options to pass to `POST` method in the
10 13
#' `httr` package.  See the details below.  Optional.
@@ -83,7 +86,7 @@
Loading
83 86
84 87
  # Overwrite the success flag if the raw_text is bad.
85 88
  if (
86 -
    any(grepl(regex_cannot_connect, raw_text)) |
89 +
    any(grepl(regex_cannot_connect, raw_text)) ||
87 90
    any(grepl(regex_empty         , raw_text))
88 91
  ) {
89 92
    success     <- FALSE  # nocov

@@ -3,8 +3,11 @@
Loading
3 3
#' @description This function reads all available data access groups from
4 4
#'   REDCap an returns them as a [base::data.frame()].
5 5
#'
6 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
7 -
#' project.  Required.
6 +
#' @param redcap_uri The
7 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
8 +
#' of the REDCap server
9 +
#' typically formatted as "https://server.org/apps/redcap/api/".
10 +
#' Required.
8 11
#' @param token The user-specific string that serves as the password for a
9 12
#' project.  Required.
10 13
#' @param http_response_encoding  The encoding value passed to
@@ -99,7 +102,7 @@
Loading
99 102
      silent = TRUE
100 103
    )
101 104
102 -
    if (exists("ds") & inherits(ds, "data.frame")) {
105 +
    if (exists("ds") && inherits(ds, "data.frame")) {
103 106
      outcome_message <- sprintf(
104 107
        "%s data access groups were read from REDCap in %0.1f seconds.  The http status code was %i.",
105 108
        format(  nrow(ds), big.mark = ",", scientific = FALSE, trim = TRUE),

@@ -4,8 +4,11 @@
Loading
4 4
#'
5 5
#' @param ds The [base::data.frame()] to be imported into the REDCap project.
6 6
#' Required.
7 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
8 -
#' project.  Required.
7 +
#' @param redcap_uri The
8 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
9 +
#' of the REDCap server
10 +
#' typically formatted as "https://server.org/apps/redcap/api/".
11 +
#' Required.
9 12
#' @param token The user-specific string that serves as the password for a
10 13
#' project.  Required.
11 14
#' @param overwrite_with_blanks A boolean value indicating if
@@ -97,7 +100,10 @@
Loading
97 100
  config_options  = NULL
98 101
) {
99 102
100 -
  csv_elements <- NULL #This prevents the R CHECK NOTE: 'No visible binding for global variable Note in R CMD check';  Also see  if( getRversion() >= "2.15.1" )    utils::globalVariables(names=c("csv_elements")) #https://stackoverflow.com/questions/8096313/no-visible-binding-for-global-variable-note-in-r-cmd-check; https://stackoverflow.com/questions/9439256/how-can-i-handle-r-cmd-check-no-visible-binding-for-global-variable-notes-when
103 +
  # This prevents the R CHECK NOTE: 'No visible binding for global variable Note in R CMD check';
104 +
  # Also see  if( getRversion() >= "2.15.1" )    utils::globalVariables(names=c("csv_elements"))
105 +
  # https://stackoverflow.com/questions/8096313/; https://stackoverflow.com/questions/9439256
106 +
  csv_elements <- NULL
101 107
102 108
  checkmate::assert_character(redcap_uri, any.missing=FALSE, len=1, pattern="^.{1,}$")
103 109
  checkmate::assert_character(token     , any.missing=FALSE, len=1, pattern="^.{1,}$")

@@ -2,8 +2,11 @@
Loading
2 2
#'
3 3
#' @description This function uses REDCap's API to download a file.
4 4
#'
5 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
6 -
#' project.  Required.
5 +
#' @param redcap_uri The
6 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
7 +
#' of the REDCap server
8 +
#' typically formatted as "https://server.org/apps/redcap/api/".
9 +
#' Required.
7 10
#' @param token The user-specific string that serves as the password for a
8 11
#' project.  Required.
9 12
#' @param record The record ID where the file is to be imported. Required

@@ -3,8 +3,11 @@
Loading
3 3
#' @description This function uses REDCap's API to select and return data.
4 4
#' This function is still in development.
5 5
#'
6 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
7 -
#' project.  Required.
6 +
#' @param redcap_uri The
7 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
8 +
#' of the REDCap server
9 +
#' typically formatted as "https://server.org/apps/redcap/api/".
10 +
#' Required.
8 11
#' @param token The user-specific string that serves as the password for a
9 12
#' project.  Required.
10 13
#' @param records An array, where each element corresponds to the ID of a
@@ -242,7 +245,7 @@
Loading
242 245
  ds_variable <- REDCapR::redcap_variables(redcap_uri, token)$data
243 246
244 247
  if (kernel$success) {
245 -
    try (
248 +
    try(
246 249
      {
247 250
        ds_eav <-
248 251
          readr::read_csv(

@@ -9,8 +9,11 @@
Loading
9 9
#' (Copied from "Export Instruments (Data Entry Forms)" method of
10 10
#' REDCap API documentation, v.10.5.1)
11 11
#'
12 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
13 -
#' project.  Required.
12 +
#' @param redcap_uri The
13 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
14 +
#' of the REDCap server
15 +
#' typically formatted as "https://server.org/apps/redcap/api/".
16 +
#' Required.
14 17
#' @param token The user-specific string that serves as the password for a
15 18
#' project.  Required.
16 19
#' @param verbose A boolean value indicating if `message`s should be printed
@@ -100,7 +103,7 @@
Loading
100 103
      #    it's under the control of the caller.
101 104
    )
102 105
103 -
    if (exists("ds") & inherits(ds, "data.frame")) {
106 +
    if (exists("ds") && inherits(ds, "data.frame")) {
104 107
      outcome_message <- sprintf(
105 108
        "%s instrument metadata records were read from REDCap in %0.1f seconds.  The http status code was %i.",
106 109
        format(nrow(ds), big.mark = ",", scientific = FALSE, trim = TRUE),
@@ -136,7 +139,7 @@
Loading
136 139
    }
137 140
  }
138 141
139 -
  if( verbose )
142 +
  if (verbose)
140 143
    message(outcome_message)
141 144
142 145
  list(

@@ -4,8 +4,11 @@
Loading
4 4
#' as a [base::data.frame()]. Each row in the data dictionary corresponds to
5 5
#' one field in the project's dataset.
6 6
#'
7 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
8 -
#' project.  Required.
7 +
#' @param redcap_uri The
8 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
9 +
#' of the REDCap server
10 +
#' typically formatted as "https://server.org/apps/redcap/api/".
11 +
#' Required.
9 12
#' @param token The user-specific string that serves as the password for a
10 13
#' project.  Required.
11 14
#' @param forms An array, where each element corresponds to the REDCap form
@@ -90,7 +93,7 @@
Loading
90 93
  forms_collapsed     <- collapse_vector(forms    , forms_collapsed)
91 94
  verbose             <- verbose_prepare(verbose)
92 95
93 -
  if (1L <= nchar(fields_collapsed) )
96 +
  if (1L <= nchar(fields_collapsed))
94 97
    validate_field_names_collapsed(fields_collapsed, stop_on_error = TRUE)
95 98
96 99
  post_body <- list(
@@ -123,7 +126,7 @@
Loading
123 126
      silent = TRUE
124 127
    )
125 128
126 -
    if (exists("ds") & inherits(ds, "data.frame")) {
129 +
    if (exists("ds") && inherits(ds, "data.frame")) {
127 130
      outcome_message <- sprintf(
128 131
        "The data dictionary describing %s fields was read from REDCap in %0.1f seconds.  The http status code was %i.",
129 132
        format(nrow(ds), big.mark = ",", scientific = FALSE, trim = TRUE),

@@ -210,7 +210,7 @@
Loading
210 210
}
211 211
212 212
# Privately-scoped function
213 -
credential_local_validation <- function (
213 +
credential_local_validation <- function(
214 214
  redcap_uri,
215 215
  token,
216 216
  username,
@@ -220,7 +220,7 @@
Loading
220 220
221 221
) {
222 222
  # Progress through the optional checks
223 -
  if (check_url & !grepl("https://", redcap_uri, perl = TRUE)) {
223 +
  if (check_url && !grepl("https://", redcap_uri, perl = TRUE)) {
224 224
    error_message_username <- paste(
225 225
      "The REDCap URL does not reference an https address.  First check",
226 226
      "that the URL is correct, and then consider using SSL to encrypt",
@@ -229,7 +229,7 @@
Loading
229 229
    )
230 230
    stop(error_message_username)
231 231
232 -
  } else if (check_username & (Sys.info()["user"] != username)) {
232 +
  } else if (check_username && (Sys.info()["user"] != username)) {
233 233
    error_message_username <- paste(
234 234
      "The username (according to R's `Sys.info()['user']` doesn't match the",
235 235
      "username in the credentials file.  This is a friendly check, and",
@@ -239,7 +239,7 @@
Loading
239 239
    )
240 240
    stop(error_message_username)
241 241
242 -
  } else if (check_token_pattern & !grepl("[A-F0-9]{32}", token, perl = TRUE)) {
242 +
  } else if (check_token_pattern && !grepl("[A-F0-9]{32}", token, perl = TRUE)) {
243 243
    error_message_token <- paste(
244 244
      "A REDCap token should be a string of 32 digits and uppercase",
245 245
      "characters.  The retrieved value was not.",
@@ -255,7 +255,7 @@
Loading
255 255
256 256
257 257
#' @export
258 -
create_credential_local <- function (path_credential) {
258 +
create_credential_local <- function(path_credential) {
259 259
  path_source <- system.file(
260 260
    "misc/example.credentials",
261 261
    package   = "REDCapR"
@@ -310,12 +310,12 @@
Loading
310 310
      "Either enclose in ",
311 311
      "quotes, or cast with `as.character()`."
312 312
    )
313 -
  } else if (!(base::missing(dsn) | base::is.null(dsn)) & !(class(dsn) %in% c("character"))) {
313 +
  } else if (!(base::missing(dsn) || base::is.null(dsn)) && !(class(dsn) %in% c("character"))) {
314 314
    stop(
315 315
      "The `dsn` parameter be a character type, or missing or NULL.  ",
316 316
      "Either enclose in quotes, or cast with `as.character()`."
317 317
    )
318 -
  } else if (!(base::missing(channel) | base::is.null(channel)) & !methods::is(channel, "DBIConnection")) {
318 +
  } else if (!(base::missing(channel) || base::is.null(channel)) && !methods::is(channel, "DBIConnection")) {
319 319
    stop("The `channel` parameter be a `DBIConnection` type, or NULL.")
320 320
321 321
  } else if (length(project_id) != 1L) {
@@ -341,8 +341,8 @@
Loading
341 341
  sql <- "EXEC [redcap].[prc_credential] @project_id = ?, @instance = ?"
342 342
  input <- list(project_id = project_id, instance = instance)
343 343
344 -
  if (base::missing(channel) | base::is.null(channel)) {
345 -
    if (base::missing(dsn) | base::is.null(dsn)) {
344 +
  if (base::missing(channel) || base::is.null(channel)) {
345 +
    if (base::missing(dsn) || base::is.null(dsn)) {
346 346
      stop(
347 347
        "The 'dsn' parameter can be missing only if a 'channel' has been ",
348 348
        "passed to 'retrieve_credential_mssql'."

@@ -113,7 +113,7 @@
Loading
113 113
114 114
#' @export
115 115
constant_to_form_completion <- function(x) {
116 -
  if (!inherits(x, "character") & !is.numeric(x)) {
116 +
  if (!inherits(x, "character") && !is.numeric(x)) {
117 117
    stop(
118 118
      "The value to recode must be a character, integer, or floating point.  ",
119 119
      "It was `",
@@ -135,7 +135,7 @@
Loading
135 135
136 136
#' @export
137 137
constant_to_form_rights <- function(x) {
138 -
  if (!inherits(x, "character") & !is.numeric(x)) {
138 +
  if (!inherits(x, "character") && !is.numeric(x)) {
139 139
    stop(
140 140
      "The value to recode must be a character, integer, or floating point.  ",
141 141
      "It was `",
@@ -158,7 +158,7 @@
Loading
158 158
159 159
#' @export
160 160
constant_to_export_rights <- function(x) {
161 -
  if (!inherits(x, "character") & !is.numeric(x)) {
161 +
  if (!inherits(x, "character") && !is.numeric(x)) {
162 162
    stop(
163 163
      "The value to recode must be a character, integer, or floating point.  ",
164 164
      "It was `",
@@ -180,7 +180,7 @@
Loading
180 180
181 181
#' @export
182 182
constant_to_access <- function(x) {
183 -
  if (!inherits(x, "character") & !is.numeric(x)) {
183 +
  if (!inherits(x, "character") && !is.numeric(x)) {
184 184
    stop(
185 185
      "The value to recode must be a character, integer, or floating point.  ",
186 186
      "It was `",

@@ -38,7 +38,7 @@
Loading
38 38
  add_unknown_level = FALSE
39 39
) {
40 40
41 -
  if (create_factor & !is.factor(scores)) {
41 +
  if (create_factor && !is.factor(scores)) {
42 42
    scores <- factor(scores)
43 43
  }
44 44
@@ -91,7 +91,7 @@
Loading
91 91
collapse_vector <- function(elements, collapsed) {
92 92
  checkmate::assert_character(collapsed, len=1, any.missing=TRUE, null.ok=TRUE)
93 93
94 -
  if ((is.null(collapsed) | length(collapsed) == 0L) | all(nchar(collapsed) == 0L)) {
94 +
  if ((is.null(collapsed) || length(collapsed) == 0L) || all(nchar(collapsed) == 0L)) {
95 95
96 96
    # This is an empty string if `elements` (eg, fields`) is NULL.
97 97
    collapsed <- dplyr::if_else(
@@ -113,6 +113,6 @@
Loading
113 113
}
114 114
115 115
## We're intentionally not exporting this function.
116 -
verbose_prepare <- function (verbose) {
116 +
verbose_prepare <- function(verbose) {
117 117
  ifelse(!is.null(verbose), verbose, getOption("verbose"))
118 118
}

@@ -7,8 +7,11 @@
Loading
7 7
#'
8 8
#' @param ds The [base::data.frame()] to be imported into the REDCap project.
9 9
#' Required.
10 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
11 -
#' project.  Required.
10 +
#' @param redcap_uri The
11 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
12 +
#' of the REDCap server
13 +
#' typically formatted as "https://server.org/apps/redcap/api/".
14 +
#' Required.
12 15
#' @param token The user-specific string that serves as the password for a
13 16
#' project.  Required.
14 17
#' @param verbose A boolean value indicating if `message`s should be printed
@@ -73,7 +76,10 @@
Loading
73 76
  verbose         = TRUE,
74 77
  config_options  = NULL
75 78
) {
76 -
  csv_elements <- NULL #This prevents the R CHECK NOTE: 'No visible binding for global variable Note in R CMD check';  Also see  if( getRversion() >= "2.15.1" )    utils::globalVariables(names=c("csv_elements")) #https://stackoverflow.com/questions/8096313/no-visible-binding-for-global-variable-note-in-r-cmd-check; https://stackoverflow.com/questions/9439256/how-can-i-handle-r-cmd-check-no-visible-binding-for-global-variable-notes-when
79 +
  # This prevents the R CHECK NOTE: 'No visible binding for global variable Note in R CMD check';
80 +
  # Also see  if( getRversion() >= "2.15.1" )    utils::globalVariables(names=c("csv_elements"))
81 +
  # https://stackoverflow.com/questions/8096313/; https://stackoverflow.com/questions/9439256
82 +
  csv_elements <- NULL
77 83
78 84
  checkmate::assert_character(redcap_uri, any.missing = FALSE, len = 1, pattern = "^.{1,}$")
79 85
  checkmate::assert_character(token     , any.missing = FALSE, len = 1, pattern = "^.{1,}$")

@@ -3,8 +3,11 @@
Loading
3 3
#' @description Exports the data set of a report created on a project's
4 4
#' 'Data Exports, Reports, and Stats' page.
5 5
#'
6 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
7 -
#' project.  Required.
6 +
#' @param redcap_uri The
7 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
8 +
#' of the REDCap server
9 +
#' typically formatted as "https://server.org/apps/redcap/api/".
10 +
#' Required.
8 11
#' @param token The user-specific string that serves as the password for a
9 12
#' project.  Required.
10 13
#' @param report_id A single integer, provided next to the report name on the
@@ -181,7 +184,7 @@
Loading
181 184
      silent = TRUE
182 185
    )
183 186
184 -
    if (exists("ds") & inherits(ds, "data.frame")) {
187 +
    if (exists("ds") && inherits(ds, "data.frame")) {
185 188
      outcome_message <- sprintf(
186 189
        "%s records and %s columns were read from REDCap in %0.1f seconds.  The http status code was %i.",
187 190
        format(  nrow(ds), big.mark = ",", scientific = FALSE, trim = TRUE),

@@ -3,8 +3,11 @@
Loading
3 3
#' @description This function reads the available logging messages from
4 4
#'   REDCap an returns them as a [base::data.frame()].
5 5
#'
6 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
7 -
#' project.  Required.
6 +
#' @param redcap_uri The
7 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
8 +
#' of the REDCap server
9 +
#' typically formatted as "https://server.org/apps/redcap/api/".
10 +
#' Required.
8 11
#' @param token The user-specific string that serves as the password for a
9 12
#' project.  Required.
10 13
#' @param log_begin_date Return the events occurring after midnight of this

@@ -11,8 +11,11 @@
Loading
11 11
#' @param continue_on_error If an error occurs while writing, should records
12 12
#' in subsequent batches be attempted.  The default is `FALSE`, which prevents
13 13
#' subsequent batches from running.  Required.
14 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
15 -
#' project.  Required.
14 +
#' @param redcap_uri The
15 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
16 +
#' of the REDCap server
17 +
#' typically formatted as "https://server.org/apps/redcap/api/".
18 +
#' Required.
16 19
#' @param token The user-specific string that serves as the password for a
17 20
#' project.  Required.
18 21
#' @param overwrite_with_blanks A boolean value indicating if

@@ -2,8 +2,11 @@
Loading
2 2
#'
3 3
#' @description List users authorized for a project.
4 4
#'
5 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
6 -
#' project.  Required.
5 +
#' @param redcap_uri The
6 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
7 +
#' of the REDCap server
8 +
#' typically formatted as "https://server.org/apps/redcap/api/".
9 +
#' Required.
7 10
#' @param token The user-specific string that serves as the password for a
8 11
#' project.  Required.
9 12
#' @param verbose A boolean value indicating if `message`s should be printed
@@ -138,7 +141,7 @@
Loading
138 141
      #   under the control of the caller.
139 142
    )
140 143
141 -
    if (exists("ds_user") & inherits(ds_user, "data.frame")) {
144 +
    if (exists("ds_user") && inherits(ds_user, "data.frame")) {
142 145
      outcome_message <- sprintf(
143 146
        "The REDCap users were successfully exported in %0.1f seconds.  The http status code was %i.",
144 147
        kernel$elapsed_seconds,

@@ -2,8 +2,11 @@
Loading
2 2
#'
3 3
#' @description Export Arms of a REDCap project
4 4
#'
5 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
6 -
#' project.  Required.
5 +
#' @param redcap_uri The
6 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
7 +
#' of the REDCap server
8 +
#' typically formatted as "https://server.org/apps/redcap/api/".
9 +
#' Required.
7 10
#' @param token The user-specific string that serves as the password for a
8 11
#' project.  Required.
9 12
#'

@@ -2,8 +2,11 @@
Loading
2 2
#'
3 3
#' @description Determines the next available record ID.
4 4
#'
5 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
6 -
#' project.  Required.
5 +
#' @param redcap_uri The
6 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
7 +
#' of the REDCap server
8 +
#' typically formatted as "https://server.org/apps/redcap/api/".
9 +
#' Required.
7 10
#' @param token The user-specific string that serves as the password for a
8 11
#' project.  Required.
9 12
#' @param verbose A boolean value indicating if `message`s should be printed

@@ -3,8 +3,11 @@
Loading
3 3
#' @description This function calls the 'exportFieldNames' function of the
4 4
#' REDCap API.
5 5
#'
6 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
7 -
#' project.  Required.
6 +
#' @param redcap_uri The
7 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
8 +
#' of the REDCap server
9 +
#' typically formatted as "https://server.org/apps/redcap/api/".
10 +
#' Required.
8 11
#' @param token The user-specific string that serves as the password for a
9 12
#' project.  Required.
10 13
#' @param verbose A boolean value indicating if `message`s should be printed
@@ -91,7 +94,7 @@
Loading
91 94
      #    it's under the control of the caller.
92 95
    )
93 96
94 -
    if (exists("ds") & inherits(ds, "data.frame")) {
97 +
    if (exists("ds") && inherits(ds, "data.frame")) {
95 98
      outcome_message <- sprintf(
96 99
        "%s variable metadata records were read from REDCap in %0.1f seconds.  The http status code was %i.",
97 100
        format(nrow(ds), big.mark = ",", scientific = FALSE, trim = TRUE),
@@ -127,7 +130,7 @@
Loading
127 130
    }
128 131
  }
129 132
130 -
  if( verbose )
133 +
  if (verbose)
131 134
    message(outcome_message)
132 135
133 136
  list(

@@ -2,8 +2,11 @@
Loading
2 2
#'
3 3
#' @description This function uses REDCap's API to select and return data.
4 4
#'
5 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
6 -
#' project.  Required.
5 +
#' @param redcap_uri The
6 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
7 +
#' of the REDCap server
8 +
#' typically formatted as "https://server.org/apps/redcap/api/".
9 +
#' Required.
7 10
#' @param token The user-specific string that serves as the password for a
8 11
#' project.  Required.
9 12
#' @param records An array, where each element corresponds to the ID of a
@@ -286,7 +289,7 @@
Loading
286 289
      silent = TRUE
287 290
    )
288 291
289 -
    if (exists("ds") & inherits(ds, "data.frame")) {
292 +
    if (exists("ds") && inherits(ds, "data.frame")) {
290 293
      outcome_message <- sprintf(
291 294
        "%s records and %s columns were read from REDCap in %0.1f seconds.  The http status code was %i.",
292 295
        format(  nrow(ds), big.mark = ",", scientific = FALSE, trim = TRUE),

@@ -8,8 +8,11 @@
Loading
8 8
#' directory. Optional.
9 9
#' @param overwrite Boolean value indicating if existing files should be
10 10
#' overwritten. Optional.
11 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
12 -
#' project.  Required.
11 +
#' @param redcap_uri The
12 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
13 +
#' of the REDCap server
14 +
#' typically formatted as "https://server.org/apps/redcap/api/".
15 +
#' Required.
13 16
#' @param token The user-specific string that serves as the password for a
14 17
#' project.  Required.
15 18
#' @param record The record ID of the instrument(s).  If empty, the responses
@@ -131,11 +134,11 @@
Loading
131 134
  if (kernel$success) {
132 135
    result_header <- kernel$result_headers$`content-type`
133 136
134 -
    if (missing(file_name) | is.null(file_name)) {
137 +
    if (missing(file_name) || is.null(file_name)) {
135 138
      file_name <- "instruments.pdf"
136 139
    }
137 140
138 -
    file_path <- if (missing(directory) & is.null(directory)) {
141 +
    file_path <- if (missing(directory) && is.null(directory)) {
139 142
      file_name # Use relative path.
140 143
    } else {
141 144
      file.path(directory, file_name) #Qualify the file with its full path.
@@ -144,7 +147,7 @@
Loading
144 147
    if (verbose)
145 148
      message("Preparing to download the file `", file_path, "`.")
146 149
147 -
    if (!overwrite & file.exists(file_path)) {
150 +
    if (!overwrite && file.exists(file_path)) {
148 151
      stop(
149 152
        "The operation was halted because the file `",
150 153
        file_path, "`

@@ -2,8 +2,11 @@
Loading
2 2
#'
3 3
#' @description Delete existing records by their ID from REDCap.
4 4
#'
5 -
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap
6 -
#' project.  Required.
5 +
#' @param redcap_uri The
6 +
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
7 +
#' of the REDCap server
8 +
#' typically formatted as "https://server.org/apps/redcap/api/".
9 +
#' Required.
7 10
#' @param token The user-specific string that serves as the password for a
8 11
#' project.  Required.
9 12
#' @param records_to_delete A character vector of the project's `record_id`
@@ -101,9 +104,9 @@
Loading
101 104
102 105
  arms_call <- redcap_arm_export(redcap_uri, token, verbose = FALSE, config_options)
103 106
104 -
  if (arms_call$has_arms & is.null(arm_of_records_to_delete)) {
107 +
  if (arms_call$has_arms && is.null(arm_of_records_to_delete)) {
105 108
    stop("This REDCap project has arms.  Please specify which arm contains the records to be deleted.")
106 -
  } else if (!arms_call$has_arms & !is.null(arm_of_records_to_delete)) {
109 +
  } else if (!arms_call$has_arms && !is.null(arm_of_records_to_delete)) {
107 110
    stop("This REDCap project does not have arms, but `arm_of_records_to_delete` is not NULL.")
108 111
  }
109 112
Files Coverage
R 95.77%
Project Totals (38 files) 95.77%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 3%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 3%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading