connect to postgre db through ssh tunnel by r

Can you show what you've done so far? It'll be easier to guide you once we get the picture of where you are in your path.

In general, RPostgres package should be quite straight-forward to use.