QRGS {lazy.mat}  R Documentation 
QR decomposition of X matrix by the Gram Schmidt orthogonalization or
Finding non redundant columns of X
QRGS(X, orth = 0, epsg = 1e09, print = 0)
X 
The input matrix. 
orth 

epsg 
crit for zero 
print 
= 1 to print the result 
Rduction is performed from left to right.
Q may contain all zero rows.
The Q matrix can be given by native qr function as
qr=qr(X)
Qfromqr=qr.qy(qr,diag(nrow(X)))[,1:ncol(X)]
Qfromqr=Qfromqr[,1:qr$rank,drop=F]
Rfromqr=solve(t(Qfromqr)%*%Qfromqr) %*% t(Qfromqr) %*% X
Xhat=Qfromqr %*% Rfromqr
This should always give XXhat == 0.
When X has all zeros rows/columns, native qr works a bit strangely.
Try qr with this X:
b=matrix(1,8,2); b[1,2]=0
X=diag(8)b %*% matSwp( t(b)%*%b ) %*% t(b)
A list of
Q n x r matrix
R r x p upper triangle matrix
P p x r upper triangle matrix to calculate Q as Q=X
rank rank of X: # of independent columns of X
maxadX max( abs( X  Q %*% R ) )
( resQRGS < QRGS(demomat(4,3)) ) demomat(4,3)  resQRGS$Q %*% resQRGS$R resQRGS$Q  demomat(4,3) %*% resQRGS$P