Problem Description
When using REDCapR with European REDCap servers, the API returns CSV data with semicolons (;) as field separators instead of commas (,). This causes REDCapR functions to fail because REDCapR functions use readr::read_csv() which is hardcoded to expect comma separators.
Current Behavior
# This fails with European REDCap servers
redcap_variables(redcap_uri = uri, token = token)
# Error: parsing issues due to semicolon separators
The raw CSV returned from European REDCap servers looks like:
field_name;form_name;section_header;field_type;field_label
record_id;demographics;;text;Study ID
name_first;demographics;;text;First Name
But REDCapR expects:
field_name,form_name,section_header,field_type,field_label
record_id,demographics,,text,Study ID
name_first,demographics,,text,First Name
So of course this leads to parsing errors
Why the existing locale parameter doesn't solve this
REDCapR functions accept a locale parameter, but this does not fix the semicolon issue because:
readr::read_csv() is hardcoded for commas - The locale parameter only affects decimal separators, date formats, and encoding, not the field delimiter
- Field delimiter is not part of locale settings -
readr::locale() cannot change the fundamental CSV structure that read_csv() expects
Proposed Solution
REDCapR should use rreadr::read_delim() (for a configurable delimiter that would work regardless of locale)
and add a delimiter parameter to REDCapR functions that allows users to specify the CSV delimiter:
# Option 1: Add delimiter parameter
redcap_variables(redcap_uri = uri, token = token, delimiter = ";")
# Option 2: Auto-detect based on locale
redcap_variables(redcap_uri = uri, token = token, locale = readr::locale(encoding = "UTF-8"))
Affected Functions
This issue affects all REDCapR functions that parse CSV responses:
redcap_read() and related functions
redcap_variables()
redcap_instruments()
redcap_event_instruments()
redcap_event_read()
redcap_metadata_read()
redcap_project_info_read()
Current Workaround
Currently, users must intercept and override REDCapR functions using assignInNamespace() to replace semicolons with commas before CSV parsing. This requires:
- Creating custom wrapper functions for each affected REDCapR function
- Using
assignInNamespace() to override the original functions
- Maintaining custom code that duplicates REDCapR's internal logic
- Regex manipulation of raw CSV text before parsing
This workaround is very cumbersome.
Problem Description
When using REDCapR with European REDCap servers, the API returns CSV data with semicolons (
;) as field separators instead of commas (,). This causes REDCapR functions to fail because REDCapR functions usereadr::read_csv()which is hardcoded to expect comma separators.Current Behavior
The raw CSV returned from European REDCap servers looks like:
But REDCapR expects:
So of course this leads to parsing errors
Why the existing
localeparameter doesn't solve thisREDCapR functions accept a
localeparameter, but this does not fix the semicolon issue because:readr::read_csv()is hardcoded for commas - Thelocaleparameter only affects decimal separators, date formats, and encoding, not the field delimiterreadr::locale()cannot change the fundamental CSV structure thatread_csv()expectsProposed Solution
REDCapR should use r
readr::read_delim()(for a configurable delimiter that would work regardless of locale)and add a
delimiterparameter to REDCapR functions that allows users to specify the CSV delimiter:Affected Functions
This issue affects all REDCapR functions that parse CSV responses:
redcap_read()and related functionsredcap_variables()redcap_instruments()redcap_event_instruments()redcap_event_read()redcap_metadata_read()redcap_project_info_read()Current Workaround
Currently, users must intercept and override REDCapR functions using
assignInNamespace()to replace semicolons with commas before CSV parsing. This requires:assignInNamespace()to override the original functionsThis workaround is very cumbersome.