【问题标题】:Can R read from a file through an ssh connection?R 可以通过 ssh 连接读取文件吗?
【发布时间】:2010-02-09 05:04:56
【问题描述】:

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

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

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

【问题讨论】:

    标签: r ssh


    【解决方案1】:

    您可以使用这样的管道读取文件:

    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 Data Import/Export 页面了解更多信息,特别是Connections 部分。

    【讨论】:

    • @james Thompson,你需要 R 中的 ssh 连接包吗?我也需要这样做,用 ssh 连接到远程服务器并读取文件。提前致谢。
    • 我尝试使用Windows R连接Linux服务器,失败了,linux服务器之间没有问题,知道吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-22
    • 1970-01-01
    • 2014-04-14
    • 2019-09-10
    • 2010-10-25
    • 2016-03-06
    相关资源
    最近更新 更多