This is not quite sufficient, I'm afraid. You cannot assume that there is only one 8.2 cluster, and that it is called 'main'. That is the default after a clean installation, but people are free to create arbitrarily many clusters.
So you should iterate over "pg_lsclusters -h" to find out valid cluster versions and names, and do the R_HOME thing for all of them.
This is not quite sufficient, I'm afraid. You cannot assume that there is only one 8.2 cluster, and that it is called 'main'. That is the default after a clean installation, but people are free to create arbitrarily many clusters.
So you should iterate over "pg_lsclusters -h" to find out valid cluster versions and names, and do the R_HOME thing for all of them.