bonifazi / TuttiFrutti

TuttiFrutti is a collection of R functions and R scripts for various utilities and tools with a focus on animal breeding and genomics.
MIT License
7 stars 0 forks source link

data.table skips is.data.frame check #20

Open bonifazi opened 2 hours ago

bonifazi commented 2 hours ago

Script: https://github.com/bonifazi/TuttiFrutti/blob/main/compute_LR_stats.R

if EBV partial and EBV whole are data.table the script returns:

val_results[[run]][[t]][[s]][[l]][[g]] <- compute_LR_stats(
                        EBV_partial = ebv.tmp[, c("AID", "sol_part" )],
                        EBV_whole   = ebv.tmp[, c("AID", "sol_whole")],
                        val_group = data.frame(AID = val.tmp[, "AID"]),
                        # val_subgroup = NA, 
                        # VAR_A = NA,
                        # inbreeding = inbreeding[[paste0("run", run)]], # inbreeding file (val group AID will be subsetted)
                        # plot = T,
                        bootstrap = F,
                        boot_samples = 10,
                        parallel = "multicore", 
                        ncpus = 15,
                        verbose = T)
Error in compute_LR_stats(EBV_partial = ebv.tmp[, c("AID", "sol_part")],  : 
  Not all IDs provided in 'val_groupIDs' were sub-set from the 'EBV_partial' and 'EBV_whole' data.frames. Make sure to provide in 'val_groupIDs' args only IDs that exist in data.frames 'EBV_partial' and 'EBV_whole'

Funny enough, the script gets stuck with no error message if bootstrap == T.

Two observations: 1) is.data.frame returns T on a data.table obj. this should be further improved as a check. 2) why bootstrap = F gives different error? confirm that some checks are not bypassed when bootstrap = F.

bonifazi commented 2 hours ago

This seems could work:

assert_that(identical(class(ebv.tmp)[1], "data.frame"),
            msg = "Input is not a pure data.frame (it might be a data.table or another structure).")

improve the error, return the class to the user.