Combine Fastq by writeFastq is not working properly
You can drastically simplify your effort because FASTQ files are simple text files; therefore, standard UNIX test file tools work:

cat refs/*.fastq &gt; combined.fastq


And this even works with .fastq.gz files — no unzipping required.



Apart from this, your R code contains several errors. For instance, your variable names change throughout, and you’re using the fsep parameter wrongly. In fact it’s unclear to me what the code is supposed to do. At an approximation (and untested), the following should work:

fastq_dir = file.path(getwd(), "refs")
fastq_files = dir(fastq_dir, pattern = "\\.fastq$", full.names = TRUE)
outfile = file.path(dirname(fastq_dir), "combined.fastq")

for (file in fastq_files) {
    fq = readFastq(file)
    writeFastq(fq, outfile, mode = "a")
}


This is equivalent to running the shell command shown above, just in a more convoluted way (parsing and re-generating the FASTQ files).