Entering edit mode
Is it possible to determine the distinct number of reads in a BAM file using countBam, if some of the fragments have both read pairs mapped and some have just one of the two reads mapped ? I want each situation to be only counted once towards the grand total.

It wouldn't be possible to easily count multi-mapping reads only once with this approach. I suppose the most general solution would be to do
length(unique(scanBam(bamFile, param = ScanBamParam(what = "qname"))[[1]][[1]])).