I cannot replicate your error. I found the data on the internet on Crawley's webpage for the book sapdecay.txt. Loading it and using dput puts in in a simple form for us to work with:
sapdecay <- structure(list(x = c(0L, 2L, 4L, 6L, 8L, 10L, 12L, 14L, 16L,
18L, 20L, 22L, 24L, 26L, 28L, 30L, 32L, 34L, 36L, 38L, 40L, 42L,
44L, 46L, 48L, 50L), y = c(1, 0.960235403, 0.844663774, 0.706936329,
0.7086414, 0.609795365, 0.513252644, 0.471399685, 0.384081274,
0.372277798, 0.334087432, 0.273307329, 0.25162333, 0.222786515,
0.210216526, 0.190591821, 0.166907195, 0.140731643, 0.12028785,
0.116460713, 0.092736872, 0.083972607, 0.088291404, 0.071790589,
0.059327414, 0.061706234)), class = "data.frame", row.names = c(NA,
-26L))
I agree with the recommendation to avoid attach:
lm(log(y)~x, sapdecay)
#
# Call:
# lm(formula = log(y) ~ x, data = sapdecay)
#
# Coefficients:
# (Intercept) x
# 0.04688 -0.05849
You may already have variables named x and/or y that are conflicting with the ones in sapdecay.