vubiostat / redcapAPI

R interface to REDCap (http://www.project-redcap.org/)
21 stars 27 forks source link

importMetaData() rejects an import of a data dictionary if any field name has just two characters or less #336

Closed ajelhajj closed 8 months ago

ajelhajj commented 8 months ago

In this case, my project has a variable called [or] (short for operating room). On import with the API, I receive the following error message:

> importMetaData(rcon = rcon.oto.dd, data = dd)

Error in importMetaData(rcon = rcon.oto.dd, data = dd) : 
  1 assertions failed:
 * The following field names do not conform to REDCap field name standards: {or}

I receive the same error message when I replace this field name with [ro]:

Error in importMetaData(rcon = rcon.oto.dd, data = dd) : 
  1 assertions failed:
 * The following field names do not conform to REDCap field name standards: {ro}

Uploading these data dictionaries using the GUI works just fine.

I've also tried renaming this field [and] to see if the rejection could also be due to [or] having any particular privileges as an operator but the metadata is successfully imported through the API when [and] is a field name.

nutterb commented 8 months ago

You're correct. Our regular expression for field names is more restrictive than REDCap field name requirements.

https://github.com/vubiostat/redcapAPI/blob/12216d232459fb3b084f682f8653d8b7a12783f5/R/constants.R#L47-L55

I'll work on a regular expression that can permit as little as a single alpha character for a field name.

This will also affect the form name regex.

nutterb commented 8 months ago

er, that didn't take as long as I thought.

REGEX_FIELD_NAME <- "(^[a-z]$|^[a-z][a-z,0-9]$|^[a-z](?!.*__.*)[a-z,0-9,_]+[a-z,0-9]$)"

field_name <- c("a", "ab", "a1", "a_1", 
                "a_", "_a", "a__1", 
                "1", "1a")

grepl(REGEX_FIELD_NAME, field_name, perl = TRUE)
[1]  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
ajelhajj commented 8 months ago

Thank you! Would it be possible to notify me when this is complete? I appreciate your help on this.

nutterb commented 8 months ago

The pull request has been submitted. It's waiting on review and QA checks.

If you want to try it out ahead of that you can install it via

devtools::install_github("vubiostat/redcapAPI", ref = "333-importFile-newRecord")

nutterb commented 8 months ago

This is now on the main branch: devtools::install_github("vubiostat/redcapAPI")