You can see the structure of the object returned by the summary function using the str function. If I store the output of a fit in an object called FIT, then I can run
str(summary(FIT))
To get the R-squared value
DF <- data.frame(Xval = 1:5, Yval = 11:15 +rnorm(5,0,2))
FIT <- lm(Yval ~ Xval, data = DF)
summary(FIT)
#>
#> Call:
#> lm(formula = Yval ~ Xval, data = DF)
#>
#> Residuals:
#> 1 2 3 4 5
#> 1.0790 -0.1979 -2.5099 1.2974 0.3313
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 9.5388 1.8462 5.167 0.0141 *
#> Xval 1.3981 0.5566 2.512 0.0868 .
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 1.76 on 3 degrees of freedom
#> Multiple R-squared: 0.6777, Adjusted R-squared: 0.5703
#> F-statistic: 6.308 on 1 and 3 DF, p-value: 0.08682
Rsqr <- summary(FIT)$r.squared
Rsqr
#> [1] 0.6777015
Created on 2020-03-13 by the reprex package (v0.3.0)