REDCapDM 1.1.0
Breaking changes
-
library(REDCapDM)no longer attaches other packages (dplyr, purrr, stringr, labelled, …): load the packages you use in your own code, e.g.library(dplyr). - REDCapR and openxlsx are now suggested packages: they are only needed to read from the REDCap API or from
.xlsxfiles and to export queries withrd_export(), which ask to install them when they are missing. - REDCapDM now requires dplyr 1.1.0 or later, and reading from the REDCap API requires REDCapR 1.2.0 or later (older versions only return the events of the first arm).
- The reports of
rd_query()andrd_event()have the unique event name (e.g.enrollment_arm_1) inEventand its label in a newEventLabelcolumn.Eventhad the label, so events with the same label (e.g. the same visit in several arms) were merged, and renaming an event in REDCap solved its queries.check_queries()also accepts the reports created with previous versions. - The
addToargument ofrd_query()andrd_event()is now calledadd_to.addTostill works, with a deprecation warning. - The
filterofrd_insert_na()must name the columns it uses (e.g.age > 30,data$ageordata[, "age"]), so that their events can be checked: a filter whose columns can’t be determined (e.g.dplyr::pull(data, "age")orget("age")) stops with an error.
New features
- New
rd_missplot()function to visualise the missing data per variable (barplot), per event and variable (heatmap in longitudinal projects) or record by record (by = "record"). First version by Ferran Perez Sanchez (#19). - Repeated instruments and repeating events are supported:
rd_query(),rd_missplot()andrd_rlogic()only use each variable in the rows where it is collected, theRepetitioncolumn and the links of the queries point to the right instance,check_queries()matches the queries by event and repetition, andrd_rlogic()evaluates the logic in each instance, as REDCap, also with[current-instance]. As a result,rd_recalculate(),rd_checkbox(),rd_dictionary()andrd_transform()also work in these projects. - New
rm_mdcandmdcarguments inredcap_data()to remove the Missing Data Codes of REDCap and of the project (rm_mdc = TRUE, the default), or to keep them (rm_mdc = FALSE) in a new<field>_mdccolumn next to each field, so that the field keeps its type. With the API, the codes of the project are read automatically. -
rd_rlogic()(and sord_recalculate(),rd_query()andrd_dictionary()) translates many more REDCap functions:isblankormissingcode(),contains(),not_contain(),starts_with(),ends_with(),left(),right(),mid(),find(),replace_text(),length(),concat(),concat_ws(),upper(),lower(),trim(),mean(),median(),stdev(),roundup(),mod(),exponential(),isnumber(),isinteger(),month()andday(), anddatediff()with"now", dates with time and time fields. It also translates the same variable in different events (e.g.[visit_2_arm_1][weight] - [visit_1_arm_1][weight]). -
rd_rlogic()returnseval_data, the evaluation next to the record identifier, event and repetition of each row. -
rd_query(),rd_event()andcheck_queries()return a report of classREDCapDM_report: printed in the console, it shows the number of queries per variable and event (per state incheck_queries()).$queries,$results,add_toandrd_export()work as before. - New
formsargument inrd_delete_vars()to remove every variable of a form. -
rd_recalculate()reports the number of different values of each calculated field,rd_insert_na()also updates the.factorversion of the variables, andrd_checkbox()returns a project without checkboxes unchanged, with a warning. - The functions take the record identifier from the dictionary (its first field) when it isn’t called
record_id, whatever its position in the data. -
filterandexpressioncan use objects created inside a function or a loop, and they are no longer run witheval(parse()).
Bug fixes
-
redcap_data()keeps the text of the values that look like numbers or missing values, with the API and with the exported files: text fields (e.g."0034","1.50"or"+34600111222"), the text"NA", the codes of options written as01or1.0,redcap_survey_identifier, and record identifiers with leading zeros or too long to be numbers. -
redcap_data()with the API gives each row the labels of its event, repeated instrument and data access group, and each field its label, by their codes and names: they were joined by position, so a change of the project while it was read could move them to other rows or fields. Text fields and the record identifier keep their labels, and yes/no, true/false and status fields get their.factorversion. -
redcap_data()with the exported files doesn’t run thelibrary(Hmisc)andgraphics.off()lines of the R script of REDCap, reads the projects that repeat events but not instruments, keeps the spaces of the labels with line breaks and accepts the paths between quotes copied by Windows. -
redcap_data()only removes the HTML tags of the labels (the texts such as<18and&are kept), and gives the same dictionary from the API and from the exported files (empty texts in the empty cells, without spaces at the start or the end). -
rd_rlogic()translates the REDCap logic as REDCap evaluates it:!=,ANDandORin capitals or across lines, negative numbers (e.g.[a]<-3or[a] < '-3'), texts between quotes that look like operators or functions (e.g.[x] = 'a=b'), blank values (different from any value with<>),if()with a condition without variables, functions written with spaces before their parenthesis, and fields whose names aren’t valid in R (e.g.if). -
rd_rlogic()evaluatesdatediff()as REDCap: it failed, and now gives the absolute difference unless the last argument istrue, with any date format,"M"for months and"m"for minutes,"today", and years and months of 365.2425 and 30.44 days. -
rd_rlogic():min()andmax()are computed row by row (they gave one value for the whole data),sum()ignores blank values,rounddown()works and rounds down, and the dates chosen byif(),min()ormax()stay dates. -
rd_rlogic()takes the value of[event][field]from the record of each row, also when the identifier isn’t calledrecord_id, without overwriting other fields, and works with variables already converted into factors withrd_factor(). -
rd_query()applies the branching logic that uses variables of other events, of checkbox options (e.g.variables = "symptoms___1"), written in R (also with[[or comments) or without fields (e.g.1 = 1), and checks each variable only in its own events. -
rd_query()keeps the texts of the expression and the values in the messages of the queries, and the characters<,>and&of the labels, describes<=and>=as “less than or equal to” and “greater than or equal to”, and keeps apart inresultsthe variables whose long names begin in the same way. -
rd_query()works withreport_zeros = TRUEwhen every variable has queries, with several data access groups when a variable has no queries, with events without records, and withby_dag = TRUEkeeps the records without a data access group. It checkslink$event_idand accepts events given by their label. -
rd_query(),rd_event()andcheck_queries()keep the record identifiers as text when they aren’t plain numbers (e.g."007"was7, and alphanumeric identifiers wereNA), write them without scientific notation (e.g.1e+05-1) and sort them naturally. -
rd_event()gives each query the data access group of its record, only reports the records of the arm of the event, works with event labels, withoutredcap_event_name.factor, withadd_toand with events without records, and takes inquery_nameone message for all the events or one per event. -
check_queries()marks asMiscorrectedonly the new queries of a field that had a query in the old report, keeps one pending query when only its link changed, tells apart queries of different fields with the same description and texts with carriage returns, reads the same text in different encodings as the same query, and works when neither report has queries. -
rd_checkbox()gives each option a valid and unique name, keeps the logic that uses the options with the codes 0 and 1 (also as numbers, e.g.[cb(1)] + [cb(2)] >= 2), translates the options with letters or negative codes, and works with tibbles, with options written as labels and with branching logic that can’t be evaluated (the options are left unchanged, with a warning). It stops when the checkboxes were already transformed. -
rd_dictionary()andrd_transform()keep the labels with quotes valid in the logic, read the options written without a space after the comma, translate the codes of yes/no and true/false fields, and keep in REDCap syntax the logic that uses factors as numbers or variables of other events. -
rd_recalculate()leaves blank the calculations without a numeric result (e.g. a division by zero), compares the values as numbers (also with labels), updates the_recalcfields that it added before instead of duplicating them, and never overwrites a field of the project called_recalc. -
rd_split()keeps the record identifier (also with another name) and the fields calledid, gives one row per record withwide = TRUE, chooses the rows of each repeating instrument by its code, keeps the rows of the forms that only repeat in some events and ignores the descriptive fields. -
rd_dates()sets toNA, with a warning, the values that aren’t dates (they stopped the function or turned the next dates intoNA), keeps the seconds of the datetimes, and works when the data doesn’t have every date field. -
rd_delete_vars()never removes the record identifier, removes the variables ofpatternfrom the dictionary without distinguishing upper and lower case, removes a checkbox from the dictionary when all its options are removed and accepts a variable with its.factorversion invars. -
rd_factor()keeps the codes of a field whose labels are of several codes, converts the.factorcolumns that are text, warns instead of stopping whenexcludehas every variable and removes the.factorcolumns without their variable, also of the REDCap columns. -
rd_insert_na()checks the events of every column of the filter, also chosen withdata$x,data[["x"]]ordata[, "x"], takes the record identifier as present in every event, accepts filters with functions and objects of the session, and works in non-longitudinal projects. -
rd_export()stops when the folder doesn’t exist or the sheet name isn’t valid in Excel, writes the links of factor columns, keeps the format of dates when the cells are centered and accepts the data frame of queries. -
rd_transform()works when the record identifier isn’t calledrecord_id(also when its form has no event) and withwide = FALSE. - All the functions work with grouped data (
dplyr::group_by()), dictionaries with factor columns and fields with the name of an internal object (e.g.dataorevent). knitr and lubridate are now declared dependencies.
Clearer messages
- Every function checks its arguments, and a wrong value stops with a message that names the argument and what it expects, instead of an internal R error.
- Errors, warnings and messages use cli and have classes (
REDCapDM_error, with_argument,_data,_file,_apiand_logic,REDCapDM_warningandREDCapDM_message). The informative messages can be hidden withoptions(REDCapDM.quiet = TRUE). - The messages name the variables, forms and events involved: e.g. the variables that don’t exist, the fields of the dictionary that aren’t in the data, how to remove missing instruments with
rd_delete_vars(forms = ...), or why a logic can’t be translated (with the translated logic and the R error). -
redcap_data()explains when a file is not found or can’t be read (e.g. a dictionary not encoded in UTF-8), and warns when variables of the data aren’t in the dictionary or the project has no records.
Documentation
- The vignette is split into four: getting started (
vignette("REDCapDM")), missing data (vignette("missing-data")), data processing (vignette("data-processing")) and queries (vignette("query-management")). - The reference of the website groups the functions by task, the help of each function links to the related ones, and the examples can be run as they are.
- New contributing guide, code of conduct and issue templates on GitHub.
-
rd_checkbox(),rd_dates(),rd_delete_vars(),rd_dictionary(),rd_export(),rd_factor(),rd_recalculate()andrd_split()are now stable.rd_missplot()remains experimental.
REDCapDM 1.0-1
Bug fixes
- Fixed a bug in
rd_checkboxthat mis-evaluated the branching logic of certain checkboxes if they had previously been transformed withrd_factor
New features
- Added a
separgument to theredcap_data()function, allowing users to specify the field separator when reading CSV dictionary files.
REDCapDM 1.0-0
Bug fixes
Addressed multiple bugs across various functions to enhance stability and reliability.
Improved error handling to provide clearer messages when issues arise.
Fixed inconsistencies in data transformation outputs for certain edge cases.
Changes & New features
-
The
rd_transformfunction has been split into several smaller subprocess functions. This allows users to:Apply each transformation step independently.
Inspect intermediate results at each stage.
Have precise control over every change made to their data.
By exposing the individual steps as separate functions, users can now customize the data transformation pipeline to better fit their REDCap datasets.
Updated function descriptions and examples illustrate how to use the subprocesses effectively, making it easier to integrate REDCapDM into data management workflows.
Some older functions related to data transformation have now been deprecated. Users are encouraged to transition to the new subprocess functions for more flexibility and maintainability.
REDCapDM 0.9-9
Bug fixes
- Added an informative message to the redcap_data() function when it is unable to replicate the factor version of a variable. This only applies to cases where the user is reading the data via an API connection. [Issue #7 in github]
- Added an informative message to the redcap_data() function when someone tries to use another type of file in the data_path argument instead of an R file. [Issue #7 in github]
REDCapDM 0.9-8
Bug fixes
- Added an informative message to the redcap_data() function when someone tries to use a URI without specifying the token or vice versa. [Issue #6 in github]
- Added an informative message to the redcap_data() function when it is unable to establish a secure connection due to an SSL certificate problem. [Issue #6 in github]
- Added examples to the redcap_data() function. [Issue #6 in github]
- Modification of the argument
delete_varsin the redcap_data() function todelete_patternto accurately describe its purpose. [Issue #6 in github] - Added a new argument to the redcap_data() function named
delete_varswhich allows users to specify variables to be removed. [Issue #6 in github]
REDCapDM 0.9-7
Bug fixes
- Error in redcap_data() function while using the API connection to import data. [Solves Issue #4 in github]
REDCapDM 0.9-0
REDCapDM 0.7-0
2023-06-02
Changes to functions
The rd_transform() function will now also transform the branching logic in the dictionary into R logic.
The rd_query() will now use the information of the event-form to automatically detect the events where the variables are present.
The rd_query() will now automatically apply the branching logic of the variable before generating queries.
Minor Changes
Remove descriptive variables from the dictionary in the redcap_data() function.
Improve the resulting summary of the rd_query() function.
New error added to the rd_query() function when trying to use a variable that is not in the dataset.
New error added to the rd_query() function when the logic of the filter was using incorrect logic.
The rd_export() function will now create a themed excel file.
REDCapDM 0.5-0
2023-03-24
Changes to functions
- New function rd_export() to export the identified queries to an excel file.
- The redcap_data() function can read the relative path to the working directory in the path arguments.
- Now rd_transform() will keep all the labels of the variables in the transformed data. Therefore, the keep_labels argument has been removed.
- rd_transform() now will also return the event_form element in the output.
- New argument exclude_recalc added to the rd_transform() function to exclude specified calculated fields from being recalculated. It may reduce the execution time in projects with complex calculated fields.
- The filter argument in the rd_query() and rd_event() functions now works as a vector so a different filter can be applied to each variable.
- Minor changes to the rd_query() function.
REDCapDM 0.4-0
2023-03-03
Changes to functions
- New link argument of the functions rd_query() and rd_event() to generate the link where the query can be found in REDCap. [Solves Issue #2 in github]
REDCapDM 0.3-0
2023-02-24
Changes to functions
- The redcap_data() function, when used to read data through an API connection, will automatically read the event-form mapping without specifying the event_path argument. This will only be applied on longitudinal REDCap projects (more than one event).
- Adaption of the rd_transform() function to non-longitudinal REDCap projects which only contain one event.
- The rd_transform() function will now also delete, by default, variables with the pattern “_timestamp” in addition to the “_complete” pattern.
- Change in the names of the categories of the different queries when comparing two reports using the check_queries().
- Creation of a new category of query in the check_queries() output (“Miscorrected”) that represents those queries that are different but belong to the same variable of the same record identifier in both the old and new reports.
- Adaptation of the summary of the check_queries() and rd_event() functions to the RStudio viewer tab.
- Customization of the title of the summary of queries returned by the check_queries() function.
REDCapDM 0.2-0
2023-02-17
Changes to functions
- New event_path argument of the function redcap_data() to read the event-form mapping of the REDCap project.
- For all functions except redcap_data() we can now pass a list with the data, dictionary and event in the first argument of the function.
- rd_transform() will now take into account the different events that might be present in the variables of the logic for the recalculation of calculated fields and the evaluation of branching logics. This also applies for rd_rlogic().
- As a consequence of this last improvement that applies in longitudinal REDCap projects (with more than one event) now we have to specify not only the data and dictionary but also the event-form mapping.
- New checkbox_na argument in rd_transform() to specify if the values of the checkbox will be converted to missing not only when the branching logic is missing but also when it’s not fulfilled (if TRUE).
- New by_dag argument in rd_query() to filter the output by each Data Access Group (DAG).
- Summary of the generated queries ( $results ) will now include the event and the type of query and will be displayed in the RStudio viewer tab.
Bug fixes
- The output of the redcap_data() function was not consistent if we read the data using the files exported from REDCap or the API connection. [Solves Issue #1 in github]
- We changed the use of the subset() function by the filter() function because of undesired behaviours of this function when applying a non-existent expression.
