In R, a formula is a symbolic representation of a model. You can create formulas from character strings, but you cannot mix symbols and character strings. For example, you could do:
lm(Y~X+Z,data = XY)
or you could do something like:
f <- as.formula(paste0("Y~",paste("X","Z",sep = "+")))
lm(formula = f,data = XY)
In your case, that means you probably need to build the formula manually each time like this:
for (i in 1: length(X)){
for (j in 1:length(X)){
f <- as.formula(paste0("Y~",paste(X[i],X[j],sep = "+")))
lm(formula = f, data=XY)
}
}
But then, this example makes little sense, since why only use the variable A-D? Why are you not looping through the other variables R, T, G, etc.? Presumably the intent was to fit models with all combinations of two covariates? Like I said, this example is rather confusing.
More generally, fitting models in the fashion is a terrible idea, and you should not do it at all. Anything you learn by fitting linear regression models one by one using every possible pair of covariates will just as likely be statistical noise as it will be signal. Not to mention the fact that as you've set this up, you will be fitting some models using the same variable twice (when i = j) in which case you will have two perfectly co-linear variables.