castoredc / castoRedc

R wrapper to Castor EDC API
MIT License
4 stars 8 forks source link

Force checkbox name to remain as is #47

Closed lcreteig closed 4 months ago

lcreteig commented 5 months ago

Proposed fix for #46.

https://github.com/castoredc/castoRedc/blob/5b50bc0f036f2674aa3e59a520690a7f2b134ea8/R/utils.R#L99-L100

as.data.frame() will replace any spaces in the list names with a .. The resulting column names in checkbox_result will therefore no longer match those in field_info.

https://github.com/castoredc/castoRedc/blob/5b50bc0f036f2674aa3e59a520690a7f2b134ea8/R/utils.R#L112-L117

Because they no longer match, a new set of columns with the original names and all values set to FALSE are created by the snippet above.

https://github.com/castoredc/castoRedc/blob/5b50bc0f036f2674aa3e59a520690a7f2b134ea8/R/utils.R#L119-L122

Finally, this snippet discards the correct columns (with the fixed names), and retains only the all-FALSE columns (with the original names).

All of this can be fixed by calling as.data.frame() with the check.names = FALSE argument, to force the original names to be retained. Because there's "data" contained within the names here (i.e. which checkbox was ticked), automatically fixing them to be proper columns names might not be a good idea here.

I've confirmed this fixes the issue for me, but it might have other unwanted downstream effects I can't oversee (like not being able to subset the data frame columns with $ without enclosing them in backticks, as the column names may now have spaces in them).

reiniervlinschoten commented 4 months ago

Interestingly, the fix does not work in my test study, diving further into this.