I'd expect getSrcFilename() also works in R not just lr. Is it a bug in the command R?
$ lr -e "source('main.R');"
[1] "main.R"
$ R --slave --no-save --no-restore --no-init-file -e "source('main.R')"
character(0)
$ cat main.R 
options(keep.source=T)
f=function() {
  getSrcFilename(f)
}
print(getSrcFilename(f))