R tips and tricks: Difference between revisions
Jump to navigation
Jump to search
Created page with "*R tips and tricks **" |
Tips and Tricks around R |
||
| Line 1: | Line 1: | ||
==R tips and tricks== | |||
** | == R in the clouds == | ||
Run a local script on a remote (fast) computer directly without RServer | |||
'''Prerequsites:''' | |||
* you can access the remote computer with 'ssh' (secure shell) from a terminal | |||
* R (and necessary packages) is installed on the remote computer | |||
* R has access to all the data that are analyzed (upload i.e. with 'rsync', 'sftp' or [https://filezilla-project.org/ filezilla]) | |||
* to see plots directly you a local X-server installed: | |||
** MacOS: [https://www.xquartz.org/ XQuarz], | |||
** Windows: | |||
**:[http://mobaxterm.mobatek.net/ MobaXterm] - a powerful X-Server with many remote access features or | |||
**:[https://sourceforge.net/projects/xming/ Xming], a minimalistic X server for Windows | |||
** Linux: ... needs nothing ;-) | |||
'''Procedure:''' | |||
# Write your R script in a(ny) text editor (perferably one with R syntax highlight mode and bracket auto-close: e.g. Geany, Gedit, TextWrangler, Atom, etc.) | |||
# Save it (Ctrl-s/Cmd-s). Do not close the editor! | |||
# Open a terminal | |||
# use commmand: | |||
#:<br /> | |||
#: ssh -X user@ssh-server 'R --slave' < ~/path-to/MyRscript.R | |||
#:<br /> | |||
#: (exchange 'user', 'ssh-server' and 'MyScript.R' accordingly; mind the ' ' in the command) | |||
# Look at your results, | |||
# modify your script, save ('Ctrl-s/Cmd-s') | |||
# re-run terminal command (use the 'up arrow' on your keyboard to get it back) | |||
'''Repeat steps 6 and 7 as often as needed''' | |||
''Comments:'' | |||
*The '--slave' flag tells R not to be interactive and show no terminal output. If you want output you need to store it locally with 'sink()' in your script | |||
*The '-X' flag in ssh allows you to have a result plot shown directly as a pop-up window. | |||
*The '~' is the sign for 'my Home directory' | |||
*In Windows exchange path separators '/' for '\' | |||
*Important: In Windows the X-Servers have to be running before conducting the R-script! | |||
*In MacOS XQuarz sometimes does not start automatically or it takes some time; start it manually if nothing shows up | |||
*In order to avoiding loggin in with password into the remote machine every time create a key pair with the commands: | |||
*:ssh-keygen (creates a private and a public key pair) | |||
*:ssh-copy-id user@ssh-server (exports the public key to the remote machine) | |||
Revision as of 15:35, 30 January 2017
R tips and tricks
R in the clouds
Run a local script on a remote (fast) computer directly without RServer
Prerequsites:
- you can access the remote computer with 'ssh' (secure shell) from a terminal
- R (and necessary packages) is installed on the remote computer
- R has access to all the data that are analyzed (upload i.e. with 'rsync', 'sftp' or filezilla)
- to see plots directly you a local X-server installed:
Procedure:
- Write your R script in a(ny) text editor (perferably one with R syntax highlight mode and bracket auto-close: e.g. Geany, Gedit, TextWrangler, Atom, etc.)
- Save it (Ctrl-s/Cmd-s). Do not close the editor!
- Open a terminal
- use commmand:
- ssh -X user@ssh-server 'R --slave' < ~/path-to/MyRscript.R
- (exchange 'user', 'ssh-server' and 'MyScript.R' accordingly; mind the ' ' in the command)
- Look at your results,
- modify your script, save ('Ctrl-s/Cmd-s')
- re-run terminal command (use the 'up arrow' on your keyboard to get it back)
Repeat steps 6 and 7 as often as needed
Comments:
- The '--slave' flag tells R not to be interactive and show no terminal output. If you want output you need to store it locally with 'sink()' in your script
- The '-X' flag in ssh allows you to have a result plot shown directly as a pop-up window.
- The '~' is the sign for 'my Home directory'
- In Windows exchange path separators '/' for '\'
- Important: In Windows the X-Servers have to be running before conducting the R-script!
- In MacOS XQuarz sometimes does not start automatically or it takes some time; start it manually if nothing shows up
- In order to avoiding loggin in with password into the remote machine every time create a key pair with the commands:
- ssh-keygen (creates a private and a public key pair)
- ssh-copy-id user@ssh-server (exports the public key to the remote machine)