redcap_write_oneshot() takes too long to run in R

redcap_write_oneshot() takes too long to run in R

par Hugo Victor Thomas Léo Najberg,
Nombre de réponses : 1

Hello,

For my study (P211) on REDCapMED, I use the R API package to automatically add data into REDCap based on the state of a training intervention hosted on another server.

The REDCap R package proposes the redcap_write_oneshot() function to update the Redcap records, but this function alone now takes nearly a minute to run (massive online study with thousands of records), which is too much for my virtual machine's cron. Is there a better, more efficient, way in R to update the Redcap records without updating the whole database like this function does?

Bests,

hugo

96 mots

Tags:
En réponse à Hugo Victor Thomas Léo Najberg

Re: redcap_write_oneshot() takes too long to run in R

par Corentin Aurèle Wicht,
Dear Hugo,

Unfortunately, the RedcapR::redcap_write_oneshot() function can only import the whole database (and not specific fields), which may be very slow in cases where the database is large.

Here is an alternative solution:

If you go under  then select  you will find at the bottom of the page: .

You can then open the "import_records.R" file and adapt it to your database and field names, as such:

library(RCurl)
library(jsonlite)

# Record ID(s)
record_id = 2

# API infos
api_token <- "YOURAPITOKEN"
api_url <- "https://redcapmed.unifr.ch/api/"

# Database of modifications to import in REDCap (field names)
record <- c(
record_id=record_id,
sql_tag=1)

# Convert to JSON
data <- jsonlite::toJSON(list(as.list(record)), auto_unbox=TRUE)

# Import in REDCap
result <- RCurl::postForm(
api_url,
token=api_token,
content='record',
format='json',
type='flat',
data=data
)
Best wishes,

C.

124 mots