Convert postGIS function

postGIS function in postgres db takes too much time to fetch results.

Is there a way to convert postGIS function in R ? I am also looking at query optimisation.

Expert recommendations welcome.

This link may be helpful with a few other links also to refer you to.