vubiostat / redcapAPI

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

Unable to delete repeated instances with deleteRecords() #409

Open bwaheed22 opened 2 weeks ago

bwaheed22 commented 2 weeks ago

I am trying to delete a specific repeated instance for a record with deleteRecords() but when I specify the record ID, instrument name and repeated instance in the function call, it deletes the entire record.

This example deletes all of record 113 instead of just repeat instance 13 in instrument 'instrument name':

deleteRecords(rcon = rc, records = '113', instrument = 'instrument name', repeat_instance = '13' )

How do I use this function to delete individual repeated instances? Can I use this function for this purpose or is there a different way to do it?

Any help is greatly appreciated!

nutterb commented 2 weeks ago

Could you report back what is returned by rc$projectInformation()$is_longitudinal. It should be either 0 (classic project) or 1 (longitudinal project). The REDCap documentation indicates that the event argument is mandatory if instrument is provided. (I'm expecting your project is not longitudinal)

nutterb commented 2 weeks ago

I will also add, I have been able to get this to delete a single instance as long as I provide the arguments arm, event, instrument, and repeat_instance.

However, if I omit any of these arguments, it deletes the data for the entire record. I will update the documentation to describe this behavior.

bwaheed22 commented 2 weeks ago

Thanks for your reply! The call rc$projectInformation()$is_longitudinal returns a 0 for me. Since it's not longitudinal, can I omit the argument arm and provide the arguments event, instrument, and repeat_instance?

nutterb commented 2 weeks ago

Yes, I'm hoping that will work. I will try to set up a non-longitudinal project to test against this evening.

Please let me know if your use of those arguments produces results.

Also, please wrap your deleteRecords command in parentheses, like below. This will print the response from the API (should be the number or records deleted)

deleteRecords(rc, records = .........)
jubilee2 commented 2 weeks ago

Hi @bwaheed22 ,

I tested the method, and it works for my project. Our REDCap is running on v14.6.4, and the is_longitudinal is 0. Here are the arguments I used:

deleteRecords(test2, records = '13', instrument = 'form2', repeat_instance = 2)