How does R's lm algorithm handle factors I thought they use discriminant analysis as discribed e.g. in chapter 4.4. in James et. al. "An Introduction to Statistical Learning with Applications in R". 
But after input from this article
and this SO-question including reproducible examples it seems that


*

*a matrix model is calculated in ans <- .External2(C_modelmatrix, t, data) (in model.matrix.default)

*the matrix model goes into z <- .Call(C_Cdqrls, x, y, tol, FALSE) and I did not expect, that linear regression and discriminant analysis are the same on the maths level. 


From here it seems, R can always use the standard algorithm based on qr-factorization.
Is that true?
Comment: R's help ?lm references Chambers, J. M. (1992) Linear models. Chapter 4 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole. But I do not have access to the book.
 A: When you have factors, a call is first made to model.matrix, to turn your formula into a design matrix $\mathbf{X}$ and a response $\mathbf{y}$. For factors that just means that the design matrix gets an extra $k−1$ columns, where $k$ is the number of categories in the factor. The reference category coincides with the intercept to prevent perfect colinearity and hence the $−1$. From there QR decomposition works no different than if it were only continuous variables. 
For a factor, the first category in levels(your_factor) is the reference level, and you could change that if needed with relevel(your_factor, "reference category").
As to your comment on why ISLR skips over QR-decomposition, I searched through the book for 'decomposition' and found this quote in chapter 10:

Problem (10.3) can be solved via an eigen decomposition, a standard
  technique in linear algebra, but details are outside of the scope of
  this book.

So I guess the answer is as simple as: Because they don't want to linger on details that aren't crucial to beginners. Remember that ISLR has a more advanced, also free version: The Elements of Statistical Learning (different authors, but very similar style). In ESL, QR-decomposition is covered in 3.2.3 (specifically, page 55). :)
A: A very useful resource is the document Coding Matrices, Contrast
Matrices and Linear
Models
by Bill Venables, available on CRAN. This explains in details how the
model matrix of a lm or glm is built, including the case where
some of the predictors are factors. The key functions contr.poly,
contr.sum, contr.treatment, contr.helmert are illustrated.
Once the model matrix is built, the estimation uses the QR
decomposition as it can be seen from the source code of
lm.
