How to run R scripts without closing X11
This looks like a similar kind of a problem.

Solutions: (taken from above source)


Just sleep via  Sys.sleep(10) which would wait ten seconds.
Wait for user input via readLines(stdin()) or something like that [untested]
Use the tcltk package which comes with R and is available on all platforms to pop up a window the user has to click to make the click disappear. That solution has been posted a few times over the years on r-help.


2nd option is better to use for the user.

P.S. Since I did not come up with the answer myself, I tried to put it in comment but my reputation is too low for that.