0

I've been using the REDCapR package to read in data from my survey form. I was reading in the data with no issue using redcap_read until I realized I needed to add a field restriction to one question on my survey. Initially it was a short answer field asking users how many of something they had, and people were doing expectedly annoying things like spelling out numbers or entering "a few" instead of a number. But all of that data read in fine. I changed the field to be a short answer field (same type as before) that requires the response to be an integer and now the data won't read into R using redcap_read.

When I run:

redcap_read(redcap_uri=uri, token=api_token)$data

I get the error message that:

Column [name of my column] can't be converted from numeric to character

I also noticed when I looked at the data that that it read in the 1st and 6th records of that column (both zeros) just fine (out of 800+ records), but everything else is NA. Is there an inherent problem with trying to read in data from a text field restricted to an integer or is there another way to do this?

Edit: it also reads the dates fine, which are text fields with a date field restriction. This seems to be very specific to reading in the validated numbers from the text field.

I also tried redcapAPI::exportRecords and it will continue to read in the rest of the dataset, but reads in NA for all values in the column with the test restriction.

wibeasley
  • 5,000
  • 3
  • 34
  • 62
lrankin07
  • 1
  • 2

1 Answers1

0

Upgrade REDCapR to the version on GitHub, which stacks the batches on top of each other before determining the data type (see #257).

# install.packages("remotes") # Run this line if the 'remotes' package isn't installed already.
remotes::install_github(repo="OuhscBbmc/REDCapR")

In your case, I believe that the batches (of 200 records, by default) contain different different data types (character & numeric, according to the error message), which won't stack on top of each other silently.

The REDCapR::redcap_read() function should work then. (If not, please create a new issue).

Two alternatives are

  1. calling redcap_read_oneshot with a large value of guess_max, or
  2. calling redcap_read_oneshot with guess_type = TRUE.
wibeasley
  • 5,000
  • 3
  • 34
  • 62