WIP: Fixed #2079

This PR fixes issue #2079, but at the moment it is still work in progress.
why this change? If r don't have an owner, it mean it isn't a Theano variable. As r must be a Theano variable, I don't see the need for this change. Also, in this case, it will work instead of crashing.

Did I miss something you need this function to work when r isn't a Variable?