massbays-tech / MassWateR

R package for working with Massachusetts surface water quality data
https://massbays-tech.github.io/MassWateR
Creative Commons Zero v1.0 Universal
11 stars 3 forks source link

qcMWRreview() field duplicate issue #44

Closed ben-wetherill closed 1 year ago

ben-wetherill commented 1 year ago

I get the following error with the following code. Attached are the files. I have narrowed the issue down to the DQO accuracy file DO saturation row. Note that I have NA for Field and Lab duplicates. Even though such duplicates are in the data, I am not interested in evaluating them. I evaluate them for DO concentration instead of DO saturation.

qcMWRreview(res=resdat, acc=dqoaccdat, frecom = dqofrecomdat, output_dir = getwd(), 
            output_file = "OARSTest_QCReport", rawdata = TRUE)
Error in `dplyr::mutate()`:
! Problem while computing `Hit/Miss = dplyr::case_when(...)`.
ℹ The error occurred in row 63.
Caused by error in `parse()`:
! <text>:1:18: unexpected numeric constant
1: 2.26171243941841 NA

OARSTest_AccuracyDQO.xlsx OARSTest_FreComDQO.xlsx OARSTest_Results_2022_noair.xlsx

fawda123 commented 1 year ago

@ben-wetherill should be fixed now, the NA entries weren't being screened correctly.

ben-wetherill commented 1 year ago

The error is now corrected.

However, I now see one more related issue. The QC Accuracy summary table is showing DO saturation in the Field Duplicates section. This should not be included because DO saturation is marked as NA for field duplicates (even though there are field duplicates in the results file). The same for the Raw Data. DO saturation field duplicates should also not be included in the raw data because we have no way of calculating Hit/Miss, and because the NA makes it just like parameters that are not in the dqo tables at all (which are ignored).

Just for reference, here is the logic I wrote down a while ago: "The QC Frequencies Summary and QC Accuracy Summary tables should show a row for each relevant parameter, regardless of whether they have QC data or not. Relevant parameters are all parameters that are in the dqofrecom file and also have Sample-Routine or Field Msr/Obs activity. One row for each relevant parameter that is not 'na' in the dqofrecom file."

Use these new files: OARSTest_FreComDQO.xlsx OARSTest_AccuracyDQO.xlsx

fawda123 commented 1 year ago

Thanks @ben-wetherill, it should be fixed now. I also added similar filters for lab duplicates, lab blanks, and field blanks.

ben-wetherill commented 1 year ago

This is fixed for the DO scenario, but I adjusted my dqofrecom file to have na's for Nitrate, and Nitrate still showed up in the QC Accuracy Summary and Raw Data. I was only able to get Nitrate to disappear by removing the value from the dqoacc file. I'm of the opinion that this should be driven completely by the dqofrecom file because that has a single entry for each matrix item and it is logically about DQO frequency, but I'm not sure if we have defined a different logic previously. What do you think?

OARSTest_FreComDQO_test.xlsx

fawda123 commented 1 year ago

@ben-wetherill that's fine, I understand that the idea is to use the DQO frequency/completeness file to screen what's returned in the accuracy summary and raw tables if the former includes empty entries. I'll need to update the tabMWRacc() and qcMWRacc() function to require the DQO frequency/completeness table as input.

ben-wetherill commented 1 year ago

I think that is the most straight-forward approach, and easiest for users to keep track of. But, let me know if you think we have taken a different position earlier. There might be other reasoning for a different approach.

fawda123 commented 1 year ago

@ben-wetherill ok, it's updated now. Note that this also kicks out the accuracy results for Depth since it is not in the DQO accuracy table.

ben-wetherill commented 1 year ago

It's looking better. Sorry there is one more thing. I think it is important that we are consistent in the multiple tables in this report.
When I include Nitrate in the dqofrecom file with NAs (as attached)...

OARSTest_FreComDQO_test.xlsx OARSTest_AccuracyDQO.xlsx

fawda123 commented 1 year ago

@ben-wetherill alright, no problem. Should be fixed now.

ben-wetherill commented 1 year ago

I think that's got it. It looks great!