A foreach loop throws an error in running parallel tasks

Can you post a reprex with representative data? See the FAQ: How to do a minimal reproducible example reprex for beginners. It doesn't have to be all the data or even your data, just so long as it acts the same way.