Can R Read from a File Through an Ssh Connection

Can R read from a file through an ssh connection?

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.

how do you connect to a remote server with ssh in R

There is direct support for ssh/scp in RCurl:

x = scp("remote.ssh.host.com", "/home/dir/file.txt", "My.SCP.Passphrase", user="username")

In R want to connect to a remote server and read a file

The scp function is provided as part of the RCurl package. If you haven't done so already, install the latest version of the package:

Open an R terminal and execute the following command to install it:

R> install.packages("RCurl", dependencies = TRUE)

If it asks about using a personal library, enter y

You will then be prompted to select a mirror. Just pick a location somewhat near you for a hopefully-quicker download speed.

Now, at the top of your R script calling scp, add the following line:

library("RCurl")

this will allow you to use scp in your R script.



Related Topics



Leave a reply



Submit