Why reinvent the wheel when I can use a built-in function.
Found here https://github.com/erictleung/dada2HPCPipe/blob/master/R/input_and_qc.R#L69-L84
See discussion on "fastqcFilter vs fastqFairedFilter vs filterAndTrim" benjjneb/dada2#311
Also, current tutorial for V1.8 shows the use of filterAndTrim https://benjjneb.github.io/dada2/tutorial.html#filter-and-trim.