Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REDCapR API rename_record to rename record_id is not supported? #513

Open
BdR76 opened this issue Nov 2, 2023 · 2 comments
Open

REDCapR API rename_record to rename record_id is not supported? #513

BdR76 opened this issue Nov 2, 2023 · 2 comments
Assignees

Comments

@BdR76
Copy link

BdR76 commented Nov 2, 2023

In REDCap we've got a project with ~700 records which were initially imported about a year ago. However, they were imported with incorrectly formatted recordIDs, without leading zero's. So the record ids are for example 1, 2, 3 etc instead of 001, 002, 003. This wasn't a problem before but now we are trying to merge data with another system and it would really be easier if they're formatted correctly, so with the leading zeros.

REDCap has an API for renaming records, see <Your Redcap env>/redcap/api/help/?content=rename_record and this would be ideal for updating all the recordIDs using an R script. So read a csv and call the API instead of doing >700 records by hand in the REDCap web application.

However, as far as I can see this API is not available as a function in the REDCapR library, is that correct? I couldn't find the rename record function (possible there are other API functions missing as well)

(REDCapR v1.1.0)

@wibeasley wibeasley self-assigned this Nov 2, 2023
@pbchase
Copy link
Contributor

pbchase commented Feb 20, 2024

@BdR76, yes, I would love to see rename_record supported in REDCapR. Until that day, I offer this example of how to do it in the redcapAPI library.

library(tidyverse)
library(redcapAPI)

record_renames <- tribble(
  ~old, ~new,
  "1", "001",
  "2", "002",
  "3", "003",
)

# Rename record
rcapi_conn <- redcapAPI::redcapConnection(
  url = Sys.getenv("URI"),
  token = Sys.getenv("TOKEN")
)

result <- purrr::map2_lgl(
  record_renames$old,
  record_renames$new,
  ~ redcapAPI::renameRecord(rcapi_conn, .x, .y)
)

rename_result <- record_renames |>
  select(old, new) |>
  bind_cols(result = result)

It's a little clunky because the redcapAPI::renameRecord is not vectorized and the result is hard to interpret when the rename is partial. My hacks with purrr::map2_lgl and bind_cols ease those pain points.

@spgarbet
Copy link

Kudos on using ENV variables to keep your api key out of code. We recently added some ENV searching to unlockREDCap as well (now it works with ENV, yaml, and an interactive key locker).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants