This function exports some of the basic attributes of a given REDCap project, such as the project's title, if it is longitudinal, if surveys are enabled, the time the project was created and moved to production. Returns a tibble::tibble().

redcap_project_info_read(
  redcap_uri,
  token,
  http_response_encoding = "UTF-8",
  locale = readr::default_locale(),
  verbose = TRUE,
  config_options = NULL,
  handle_httr = NULL
)

Arguments

redcap_uri

The uri/url of the REDCap server typically formatted as "https://server.org/apps/redcap/api/". Required.

token

The user-specific string that serves as the password for a project. Required.

http_response_encoding

The encoding value passed to httr::content(). Defaults to 'UTF-8'.

locale

a readr::locale() object to specify preferences like number, date, and time formats. This object is passed to readr::read_csv(). Defaults to readr::default_locale().

verbose

A boolean value indicating if messages should be printed to the R console during the operation. The verbose output might contain sensitive information (e.g. PHI), so turn this off if the output might be visible somewhere public. Optional.

config_options

A list of options passed to httr::POST(). See details at httr::httr_options(). Optional.

handle_httr

The value passed to the handle parameter of httr::POST(). This is useful for only unconventional authentication approaches. It should be NULL for most institutions. Optional.

Value

Currently, a list is returned with the following elements:

  • data: An R tibble::tibble() of all data access groups of the project.

  • success: A boolean value indicating if the operation was apparently successful.

  • status_codes: A collection of http status codes, separated by semicolons. There is one code for each batch attempted.

  • outcome_messages: A collection of human readable strings indicating the operations' semicolons. There is one code for each batch attempted. In an unsuccessful operation, it should contain diagnostic information.

  • elapsed_seconds: The duration of the function.

Details

Timezones

Several datetime variables are returned, such as the project's creation_time. For the time to be meaningful, you'll need to set the time zone because this function uses readr::read_csv(), which assigns UTC if no timezone is specified. Find your server's location listed in base::OlsonNames(), and pass it to readr's readr::locale() function, and then pass that to redcap_project_info_read(). See the examples below

For more timezone details see the Timezones section of readr's locales vignette.

Columns not yet added This function casts columns into data types that we think are most natural to use. For example, in_production is cast from a 0/1 to a boolean TRUE/FALSE. All columns not (yet) recognized by REDCapR will be still be returned to the client, but cast as a character. If the REDCap API adds a new column in the future, please alert us in a REDCapR issue and we'll expand the casting specifications.

External Modules

A project's external_modules cell contains all its approved EMs, separated by a column. Consider using a function like tidyr::separate_rows() to create a long data structure.

References

The official documentation can be found on the 'API Help Page' and 'API Examples' pages on the REDCap wiki (i.e., https://community.projectredcap.org/articles/456/api-documentation.html and https://community.projectredcap.org/articles/462/api-examples.html). If you do not have an account for the wiki, please ask your campus REDCap administrator to send you the static material.

Author

Will Beasley, Stephan Kadauke

Examples

# \dontrun{
# Specify your project uri and token(s).
uri                  <- "https://bbmc.ouhsc.edu/redcap/api/"
token_simple         <- "9A81268476645C4E5F03428B8AC3AA7B"
token_longitudinal   <- "0434F0E9CF53ED0587847AB6E51DE762"

# ---- Simple examples
REDCapR::redcap_project_info_read(uri, token_simple      )$data
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> # A tibble: 1 × 26
#>   project_id project_t…¹ creation_time       production_time in_produc…² proje…³
#>        <int> <chr>       <dttm>              <dttm>          <lgl>       <chr>  
#> 1        153 REDCapR Ta… 2013-11-29 15:58:20 NA              FALSE       English
#> # … with 20 more variables: purpose <int>, purpose_other <chr>,
#> #   project_notes <chr>, custom_record_label <chr>,
#> #   secondary_unique_field <chr>, is_longitudinal <lgl>,
#> #   has_repeating_instruments_or_events <lgl>, surveys_enabled <lgl>,
#> #   scheduling_enabled <lgl>, record_autonumbering_enabled <lgl>,
#> #   randomization_enabled <lgl>, ddp_enabled <lgl>, project_irb_number <chr>,
#> #   project_grant_number <chr>, project_pi_firstname <chr>, …
REDCapR::redcap_project_info_read(uri, token_longitudinal)$data
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
#> # A tibble: 1 × 26
#>   project_id project_t…¹ creation_time       production_time in_produc…² proje…³
#>        <int> <chr>       <dttm>              <dttm>          <lgl>       <chr>  
#> 1        212 REDCapR Ta… 2014-08-31 13:07:55 NA              FALSE       English
#> # … with 20 more variables: purpose <int>, purpose_other <chr>,
#> #   project_notes <chr>, custom_record_label <chr>,
#> #   secondary_unique_field <chr>, is_longitudinal <lgl>,
#> #   has_repeating_instruments_or_events <lgl>, surveys_enabled <lgl>,
#> #   scheduling_enabled <lgl>, record_autonumbering_enabled <lgl>,
#> #   randomization_enabled <lgl>, ddp_enabled <lgl>, project_irb_number <chr>,
#> #   project_grant_number <chr>, project_pi_firstname <chr>, …

# ---- Specify timezone
# Specify the server's timezone, for example, US Central
server_locale <- readr::locale(tz = "America/Chicago")
d3 <-
  REDCapR::redcap_project_info_read(
    uri,
    token_simple,
    locale     = server_locale
  )$data
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
d3$creation_time
#> [1] "2013-11-29 15:58:20 CST"

# Alternatively, set timezone to the client's location.
client_locale <- readr::locale(tz = Sys.timezone())

# ---- Inspect multiple projects in the same tibble
# Stack all the projects on top of each other in a (nested) tibble,
#   starting from a csv of REDCapR test projects.
# The native pipes in this snippet require R 4.1+.
d_all <-
  system.file("misc/example.credentials", package = "REDCapR") |>
  readr::read_csv(
    comment     = "#",
    col_select  = c(redcap_uri, token),
    col_types   = readr::cols(.default = readr::col_character())
  ) |>
  dplyr::filter(32L == nchar(token)) |>
  purrr::pmap_dfr(REDCapR::redcap_project_info_read, locale = server_locale)
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.3 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.3 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.3 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.6 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.4 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.2 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.
#> 1 rows were read from REDCap in 0.1 seconds.  The http status code was 200.

# Inspect values stored on the server.
d_all$data
#> # A tibble: 30 × 26
#>    project_id project_…¹ creation_time       production_time in_produc…² proje…³
#>         <int> <chr>      <dttm>              <dttm>          <lgl>       <chr>  
#>  1        153 REDCapR T… 2013-11-29 15:58:20 NA              FALSE       English
#>  2        212 REDCapR T… 2014-08-31 13:07:55 NA              FALSE       English
#>  3        213 REDCapR T… 2014-08-31 13:34:06 NA              FALSE       English
#>  4        268 REDCapR R… 2015-02-21 12:18:27 NA              FALSE       English
#>  5        690 REDCapR T… 2017-08-21 22:14:37 NA              FALSE       English
#>  6        691 REDCapR T… 2017-08-21 22:24:45 NA              FALSE       English
#>  7        753 REDCapR T… 2017-12-01 08:58:07 NA              FALSE       English
#>  8        817 REDCapR T… 2018-03-06 15:46:24 NA              FALSE       English
#>  9        977 REDCap Ta… 2018-08-24 11:30:21 NA              FALSE       English
#> 10        998 REDCapR T… 2018-09-11 18:21:14 NA              FALSE       English
#> # … with 20 more rows, 20 more variables: purpose <int>, purpose_other <chr>,
#> #   project_notes <chr>, custom_record_label <chr>,
#> #   secondary_unique_field <chr>, is_longitudinal <lgl>,
#> #   has_repeating_instruments_or_events <lgl>, surveys_enabled <lgl>,
#> #   scheduling_enabled <lgl>, record_autonumbering_enabled <lgl>,
#> #   randomization_enabled <lgl>, ddp_enabled <lgl>, project_irb_number <chr>,
#> #   project_grant_number <chr>, project_pi_firstname <chr>, …
# or: View(d_all$data)

# Inspect everything returned, including values like the http status code.
d_all
#> # A tibble: 30 × 6
#>    data$pr…¹ $proj…² $creation_time      success statu…³ outco…⁴ elaps…⁵ raw_t…⁶
#>        <int> <chr>   <dttm>              <lgl>     <int> <chr>     <dbl> <chr>  
#>  1       153 REDCap… 2013-11-29 15:58:20 TRUE        200 1 rows…   0.205 ""     
#>  2       212 REDCap… 2014-08-31 13:07:55 TRUE        200 1 rows…   0.276 ""     
#>  3       213 REDCap… 2014-08-31 13:34:06 TRUE        200 1 rows…   0.152 ""     
#>  4       268 REDCap… 2015-02-21 12:18:27 TRUE        200 1 rows…   0.158 ""     
#>  5       690 REDCap… 2017-08-21 22:14:37 TRUE        200 1 rows…   0.142 ""     
#>  6       691 REDCap… 2017-08-21 22:24:45 TRUE        200 1 rows…   0.139 ""     
#>  7       753 REDCap… 2017-12-01 08:58:07 TRUE        200 1 rows…   0.170 ""     
#>  8       817 REDCap… 2018-03-06 15:46:24 TRUE        200 1 rows…   0.131 ""     
#>  9       977 REDCap… 2018-08-24 11:30:21 TRUE        200 1 rows…   0.139 ""     
#> 10       998 REDCap… 2018-09-11 18:21:14 TRUE        200 1 rows…   0.131 ""     
#> # … with 20 more rows, 23 more variables: data$production_time <dttm>,
#> #   $in_production <lgl>, $project_language <chr>, $purpose <int>,
#> #   $purpose_other <chr>, $project_notes <chr>, $custom_record_label <chr>,
#> #   $secondary_unique_field <chr>, $is_longitudinal <lgl>,
#> #   $has_repeating_instruments_or_events <lgl>, $surveys_enabled <lgl>,
#> #   $scheduling_enabled <lgl>, $record_autonumbering_enabled <lgl>,
#> #   $randomization_enabled <lgl>, $ddp_enabled <lgl>, …
# }