-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected Behavior: Field validation type number_comma_decimal
breaks in export
#366
Comments
@joundso, to make sure I understand correctly: you're proposing that Can you confirm this works? It is a variation of https://ouhscbbmc.github.io/REDCapR/articles/workflow-read.html#specify-everything-is-a-character. Everything is kept as a string, and then you convert each column explicitly, after manually determining if it uses a comma or period as the separator. col_types <- readr::cols(.default = readr::col_character())
ds1 <-
REDCapR::redcap_read(
redcap_uri = Sys.getenv("REDCAP_API_URL_TEST"),
token = Sys.getenv("REDCAP_API_KEY_TEST"),
col_types = col_types
) |>
dplyr::mutate(
test_comma = readr::parse_number(test_comma, locale = readr::locale(decimal_mark = ",")),
test_dot = readr::parse_number(test_dot , locale = readr::locale(decimal_mark = ".")),
) For a REDCap project that doesn't mix & match separators, I'm thinking there's a way to pass/incorporate a dataset-wide value of REDCapR/R/redcap-read-oneshot.R Lines 262 to 275 in 5910539
I don't think I've ever needed to use commas as separators. Do you use readr? How do you personally prefer to specify commas as the separator when you read a normal csv into R? |
@wibeasley Sorry for the delay - Yes exactly!
|
Great, in the inst/test-data/, can you please add a data dictionary & a data file that tightly operationalizes your desired output? So you're confident that if REDCapR can read this project, then it's working as expected. Similar to inst/test-data/project-simple/simple-data.csv, but without the metadata file. (I'll add that.) Maybe the directory is called "inst/test-data/decimal-comma/", and the two files are "decimal-comma.csv" and "decimal-comma-data-dictionary.csv". Maybe 5 variables and 10 rows. But I'll let you decide whatever allows the tightest scenario to assure the package is producing the desired output. |
Just added a very rudimentary demo dataset in #374 if it helps. |
@joundso, for those comma-decimal fields, I see your value is "number_comma_decimal" for I like the idea and I've seem other people use them, but I never have. Will this be different on other REDCap projects? What about on other REDCap instances? |
@wibeasley The field-validation type |
@wibeasley Absolutely! Many thanks for the kind enquiry and especially for the stringent and instructive implementation! In my view, there is nothing more that needs to be added. Especially nothing that is worth delaying the CRAN submission. |
It seems that number-fields with the validation
number_comma_decimal
are exported or casted as doubles but with removed decimal separator (the comma).How to reproduce
1.5
(as value for the "normal" number field) and1,5
(as value for the comma separated field)REDCapR::redcap_read()
:Here (in the last line) I would assume that the result would be
1.5
for both fields. But15
as result for the input1,5
(with the comma as decimal separator) is of course not correct.System environment
Created on 2021-11-11 by the reprex package (v2.0.1)
Thank you
Thanks for your great work so far! If I am missing anything, please let me know!
The text was updated successfully, but these errors were encountered: