Closed BardinetSam closed 9 months ago
Thanks for reaching out to us, @BardinetSam.
Would you be able to run the first three trouble shooting steps at https://github.com/vubiostat/redcapAPI?tab=readme-ov-file#report-issues-or-problems
Do you know if your missing data codes are numeric (-99) or character (UNK)?
Thank you for your reply, Here's what I got as I went along the first three trouble shooting steps:
1) Rec <- exportRecordsTyped(rcon):
_In .castRecordsattachInvalid(rcon = rcon, Records = Records, Raw = Raw, :
Some records failed validation. Use reviewInvalidRecords
to review the failures.
2) exportRecordsTyped(rcon, validation = skip_validation, cast = rawcast)
#Erreur : object 'skip_validation' not found_
I tried with redcapAPI::exportRecords(rcon_old, validation = skip_validation, cast = raw_cast)
_In withCallingHandlers(warning = function(w) { :
colname: NAs introduced during automatic conversion
3) Yes
Missing data codes are characters, hence the conflict when they are exported in a column of numbers.
Thanks, @BardinetSam . Those answers are really helpful in understanding the behavior you're seeing.
It looks like we've had a few updates since you last updated redcapAPI
. We just published version 2.8.4 to CRAN on 31 January. I would recommend you get the latest version using install.packages("redcapAPI")
.
After this update, you can run exportRecordsTyped(rcon, validation = skip_validation, cast = raw_cast)
, and I would expect that will return your data set without any casting (formatting with the data dictionary) whatsoever. In fact, all of your fields will be returned as characters, giving you a chance to inspect them and review the missing data codes.
If there is only a single field for which you want to skip casting, you can write a custom casting function that applies the casting to all of the number fields except the one you want to remain character. It would look something like this
my_number_cast <- function(x, field_name, coding){
if (field_name %in% c("number_field_to_stay_character") x else as.numeric(x)
}
Rec <- exportRecordsTyped(rcon,
validation = skip_validation,
cast = list(number = my_number_cast)
You can read more about what redcapAPI is doing with your data by reading the vignettes about missing data detection, data validation, and casting data
Please reply and let us know if these suggestions have helped you get the data in the format you are wanting.
He might be able to get by with just a custom NA handler.
Hello to both of you, and thank you for your answers and your time.
The command :exportRecordsTyped(rcon, validation = skip_validation, cast = raw_cast)
worked finally, Basic R error: I wasn't calling the library by doing library(redcapAPI)
but I was calling it using redcapAPI::exportRecordsTyped()
, which is why it gave me the error #Error: object 'skip_validation' not found
.
To sum up, for my code to work, I had to use one of these two lines of code:
library(redcapAPI) exportRecordsTyped(rcon, validation = skip_validation, cast = raw_cast)
or
redcapAPI::exportRecordsTyped(rcon, validation = redcapAPI::skip_validation, cast = redcapAPI::raw_cast)
Thank you again for your invaluable help and investment.
Have a nice day.
Samuel BARDINET
redcapAPI::_some_function_
says access a function in that library without it being in the present global namespace.
library(redcapAPI)
says load all functions exported by the library into the global namespace for access without the namespace specifier. I would recommend this if one is doing much work with the library.
I think based on your comments you will want to use exportRecordsTyped
without the raw specifiers and a custom NA function. What are the possible character encodings of missing values in your project? If you share that I can write you an example snippet that does that and the rest of the data typing into memory can continue per the defaults.
In my project, some of the variables I export are of "number" type but have a "missing data code value", and this causes problems when exporting because these values are replaced by NA.
I've already tried without success:
Is there any particular parameter to be used in
exportRecords()
orexportRecordsTyped()
in order to export this type of data? Thanks in advance