The newdata
parameter should be a data.frame
with column names matching the names used as covariates. So the correct case is
predict(lm(x~y),newdata=data.frame(y=2.5))
or
predict(lm(y~x),newdata=data.frame(x=2.5))
depending on which way you wanted to do the regression.