OuhscBbmc / REDCapR
Showing 1 of 1 files from the diff.

@@ -155,6 +155,56 @@
Loading
155 155
  config_options                = NULL
156 156
) {
157 157
158 +
  meat <-
159 +
    redcap_metadata_internal(
160 +
      redcap_uri,
161 +
      token,
162 +
      http_response_encoding,
163 +
      locale,
164 +
      verbose,
165 +
      config_options
166 +
    )$d_variable %>%
167 +
    dplyr::pull(.data$aligned)
168 +
169 +
  # Construct an explanation header that's aligned with the col_types output
170 +
  gaps <- unlist(gregexpr("[=#]", meat[1]))
171 +
  header <- sprintf(
172 +
    "  # %-*s %-*s %s\n",
173 +
    gaps[1] - 4,
174 +
    "[field]",
175 +
    gaps[2] - gaps[1] - 1,
176 +
    "[readr col_type]",
177 +
    "[explanation for col_type]"
178 +
  )
179 +
180 +
  # Sandwich the col_types output in between the opening+header and the closing
181 +
  sandwich <-
182 +
    # I'd prefer this approach, but the `.` is causing problems with R CMD check.
183 +
    paste0(
184 +
      "# col_types <- readr::cols_only( # Use `readr::cols_only()` to restrict the retrieval to only these columns\n",
185 +
      "col_types <- readr::cols( # Use `readr::cols()` to include unspecified columns\n",
186 +
      header,
187 +
      paste(meat, collapse = "\n") ,
188 +
      "\n)\n"
189 +
    )
190 +
191 +
  sandwich %>%
192 +
    message()
193 +
194 +
  eval(str2expression(sandwich))
195 +
}
196 +
197 +
#' @importFrom magrittr %>%
198 +
redcap_metadata_internal <- function(
199 +
    redcap_uri,
200 +
    token,
201 +
202 +
    http_response_encoding        = "UTF-8",
203 +
    locale                        = readr::default_locale(),
204 +
    verbose                       = FALSE,
205 +
    config_options                = NULL
206 +
) {
207 +
158 208
  checkmate::assert_character(redcap_uri                , any.missing=FALSE, len=1, pattern="^.{1,}$")
159 209
  checkmate::assert_character(token                     , any.missing=FALSE, len=1, pattern="^.{1,}$")
160 210
@@ -250,7 +300,8 @@
Loading
250 300
  # [1] "signature"   "file_upload" "descriptive"
251 301
252 302
  # Translate the four datasets into a single `readr:cols()` string printed to the console
253 -
  meat <-
303 +
  # meat <-
304 +
  d <-
254 305
    d_meta %>%
255 306
    dplyr::mutate(
256 307
      autonumber  = (.autonumber & (.data$field_name == .record_field)),
@@ -339,33 +390,19 @@
Loading
339 390
      # Pad the left side before appending the right side.
340 391
      aligned = sprintf("  %-*s = readr::%-*s, # %s", .data$padding1, .data$field_name, .data$padding2, .data$readr_col_type, .data$explanation)
341 392
    ) %>%
342 -
    dplyr::pull(.data$aligned)
343 -
344 -
  # Construct an explanation header that's aligned with the col_types output
345 -
  gaps <- unlist(gregexpr("[=#]", meat[1]))
346 -
  header <- sprintf(
347 -
    "  # %-*s %-*s %s\n",
348 -
    gaps[1] - 4,
349 -
    "[field]",
350 -
    gaps[2] - gaps[1] - 1,
351 -
    "[readr col_type]",
352 -
    "[explanation for col_type]"
353 -
  )
354 -
355 -
  # Sandwich the col_types output in between the opening+header and the closing
356 -
  sandwich <-
357 -
    # I'd prefer this approach, but the `.` is causing problems with R CMD check.
358 -
    paste0(
359 -
      "# col_types <- readr::cols_only( # Use `readr::cols_only()` to restrict the retrieval to only these columns\n",
360 -
      "col_types <- readr::cols( # Use `readr::cols()` to include unspecified columns\n",
361 -
      header,
362 -
      paste(meat, collapse = "\n") ,
363 -
      "\n)\n"
393 +
    dplyr::select(
394 +
      .data$field_name,
395 +
      .data$field_type,
396 +
      validation_type           = .data$vt,
397 +
      .data$autonumber,
398 +
      # .data$response,
399 +
      .data$readr_col_type,
400 +
      # .data$explanation,
401 +
      # .data$padding1,
402 +
      # .data$padding2,
403 +
      .data$aligned,
364 404
    )
365 405
366 -
  sandwich %>%
367 -
    message()
368 -
369 406
  decimal_period_any <- any(d_meta$vt %in% c("number", "number_1dp", "number_2dp", "number_3dp", "number_4dp" ))
370 407
  decimal_comma_any  <- any(d_meta$vt %in% c("number_comma_decimal", "number_1dp_comma_decimal", "number_2dp_comma_decimal", "number_3dp_comma_decimal", "number_4dp_comma_decimal"))
371 408
@@ -382,5 +419,7 @@
Loading
382 419
    )
383 420
  }
384 421
385 -
  eval(str2expression(sandwich))
422 +
  list(
423 +
    d_variable = d
424 +
  )
386 425
}
Files Coverage
R 97.84%
Project Totals (40 files) 97.84%
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