With the plugin External Tools you can comfortably run the script while you write it in gedit. After installing the plugin, go to Tools > Manage External Tools and create your own entrys and keyboard shortcuts.
For running a shell script I simply added:
and chose the Current Document as input. You’ll see the output in the bottom panel (Ctrl+F9).
For running an R script you simply add
#!/bin/bash /usr/bin/R --no-save
and chose the Current Document as input. The output is as well shown in the bottom panel.