Skip to content

importUserRoles fails due to static column selection in exportUserRoles #502

@jubilee2

Description

@jubilee2

The importUserRoles function fails with undefined columns selected because it triggers an internal call to exportUserRoles, which attempts to subset the UserRole data frame using a static vector: REDCAP_USER_ROLE_TABLE_ACCESS_VARIABLES.

Based on the REDCap configurations, the API does not return the full set of these variables. The package should dynamically identify which columns exist before attempting to reassign factors or subset the data.

Error Trace

Error in `[.data.frame`(UserRole, REDCAP_USER_ROLE_TABLE_ACCESS_VARIABLES) : 
  undefined columns selected
Calls: importUserRoles ... exportUserRoles.redcapApiConnection -> lapply -> [ -> [.data.frame
Image

Suggested Fix

Modify the internal subsetting logic to intersect the requested variables with the actual names present in the data frame:

# Current problematic logic likely resembles:
# UserRole[, REDCAP_USER_ROLE_TABLE_ACCESS_VARIABLES]

# Proposed dynamic logic:
existing_vars <- intersect(REDCAP_USER_ROLE_TABLE_ACCESS_VARIABLES, names(UserRole))
UserRole[, existing_vars]

https://github.com/vubiostat/redcapAPI/blob/main/R/exportUserRoles.R#L86

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions