Thank you to everyone who has replied to my message it has certainly given me new avenues to try. I think Robert may have lived in dunfermline and I think if tried there the nearest prison would have been Dundee. He never married and died in the poorhouse in Dunfermline. I know Robert was in Dundee Prison as when I was at the records office in Edinburgh and I looked up the census I had to ask which prison he was in and the man went and looked it up and told me it was Dundee Prison Bell St. It was later demolished and Perth Prison was then used.
There was a prison in Dundee and the last death by hanging in Dundee prison was on 24th April 1889, it was William Bury the man thought to be Jack the Ripper. It is a very interesting story and it can be found at:
www.dundeemessenger.co.uk/myths