humm, there are some reports of incompatibilities with something like ggplot2 and R 4,1.x but I do not remember them affecting things like lm()
Can you give us a reproducible example (reprex)
We probably need to step through tnhe code to get a feel for what is happening.
A handy way to supply sample data is to use the dput() function. See ?dput. If you have a very large data set then something like head(dput(myfile), 100) will likely supply enough data for us to work with.