Nobody would write R code the way this book is teaching. For that matter, nobody looking to do linear regression for data science in Python is doing their own matrix math, either.
Linear regression should be regarded as the statistical equivalent of stripping down a rifle, reassembling it and checking its function. If you develop any statistical software, you're going to end up doing it at some point.