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
Alternatives to Nested Ifelse Statements in R
Where Should I Put Data for Automated Tests with Testthat
How to Create a Different Report for Each Subset of a Data Frame with R Markdown
Names of R's Available Packages
Storing Specific Xml Node Values with R's Xmleventparse
Justification of Multiple Legends in Ggmap/Ggplot2
How to Skip an Error in a Loop
Ggplot2 - Multi-Group Histogram with In-Group Proportions Rather Than Frequency
Differencebetween Names and Colnames
R Dplyr Filter Not Masking Base Filter
Join Data.Table on Exact Date or If Not the Case on the Nearest Less Than Date