You can extract X-square statistic this way:
chisq.test(c(89,37,30,28,2), c(40,20,20,15,5)) -> test
test$statistic
# X-squared
# 15
And than just find the maximum value. But it would be easier to help if your example were reproducible.
2
solved Transform the form of the function’s result and get the maximum value