Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can R read from a file through an ssh connection?

Tags:

R can read files on a web server using convenient syntax such as

data <- read.delim("http://remoteserver.com/file.dat")

I wonder if there is a way to do something similar with a file on an ssh server with passwordless-ssh already in place?

like image 477
hatmatrix Avatar asked Feb 09 '10 05:02

hatmatrix


People also ask

Can SSH be used for file transfer?

An SSH client is a software which uses the SSH protocol to connect to a remote computer. In general SSH protocol can be used for two purposes, file transfers and terminal access.

How do I connect to a remote using SSH?

To initiate an SSH connection to a remote system, you need the Internet Protocol (IP) address or hostname of the remote server and a valid username. You can connect using a password or a private and public key pair. Because passwords and usernames can be brute-forced, it's recommended to use SSH keys.


1 Answers

You can read a file using pipes like this:

d = read.table( pipe( 'cat data.txt' ), header = T )

If you wanted to read from an SSH connection, try this:

d = read.table( pipe( 'ssh hostname "cat data.txt"' ), header = T )

There's also no reason to confine this to just ssh commands, you could also do something like this:

d = read.table( pipe( 'cat *.txt' ) )

See the R Data Import/Export page for more information, specifically the Connections section.

like image 56
James Thompson Avatar answered Sep 17 '22 16:09

James Thompson