rtmill / Data-Quality-Analysis

The PEDSnet Data Quality Assessment Toolkit (OMOP CDM)
BSD 2-Clause "Simplified" License
1 stars 0 forks source link

dev.off() causing error when null #5

Open rtmill opened 5 years ago

rtmill commented 5 years ago

In some cases the device is null, not sure why. Need to check if it is null before turning off. error: Error in dev.off() : cannot shut down device 1 (the null device)

Can use:

dev.cur returns a length-one named integer vector giving the number and name of the active device, or 1, the null device, if none is active.

e.g. from:

describeOrdinalField<-function(table_df, table_name,field_name, group_ret = 1, ggplotting = T)
{
    ...
    dev.off()
    return(return_message)
}

to:

describeOrdinalField<-function(table_df, table_name,field_name, group_ret = 1, ggplotting = T)
{
    ...
    if(dev.cur() != 1){
      dev.off()
    }
    return(return_message)
}