Search code examples
rimportfactorsredcap

How to use exportRecordsTyped function from the redcapAPI package to import the data without factors?


I had previously used the following code to import data from REDCap:

data.df <- redcapAPI::exportRecords(rcon, 
                             forms = c("setup_log"),
                             labels = FALSE, 
                             factors = FALSE)

Because the exportRecords function is deprecated, I would like to use the new exportRecordsTyped function from the redcapAPI package. However, it seems to import all the strings as factors, which I do not want: the rest of my code relies on them not being factors.

I have been looking through the help page for exportRecordsTyped, but I have not found a way to import all the columns not as factors. I would like something like factors = FALSE, which does not seem to exist in the new exportRecordsTyped. Is there a way that I can do this?

I have found a way to do this with the REDCapR package redcap_read_oneshot function as follows, but I am still wondering if there is a way to do this with exportRecordsTyped.

data.df <- REDCapR::redcap_read_oneshot(Redcap.url,
                                        Redcap.token,
                                        forms = c("setup_log"),
                                        verbose = FALSE
                                        )$data 

Thanks.


Solution

  • There is an alternative package for the redcap API: REDCapR. Its function redcap_read_oneshot() does not convert strings to factors.

    rc_data <- 
      redcap_read_oneshot(
      redcap_uri = "https://<url/ip to your redcap instance here>/api/",
      token = "your redcap API key here")
    
    rc_data$data