R 可以通过 ssh 连接读取文件吗? [英] Can R read from a file through an ssh connection?

查看:29
本文介绍了R 可以通过 ssh 连接读取文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R 可以使用方便的语法读取 Web 服务器上的文件,例如

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

我想知道是否有一种方法可以对 ssh 服务器上的文件执行类似的操作,并且无密码 ssh 已经到位?

解决方案

你可以像这样使用管道读取文件:

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

如果你想从 SSH 连接中读取数据,试试这个:

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

也没有理由将其限制为 ssh 命令,您也可以执行以下操作:

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

请参阅 R 数据导入/导出页面欲了解更多信息,特别是 Connections 部分.>

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?

解决方案

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.

这篇关于R 可以通过 ssh 连接读取文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆