替代在R系统()调用SED,rsync的,SSH等:做功能存在,我应该写我自己的,还是我错过了点? [英] Alternatives to system() in R for calling sed, rsync, ssh etc.: Do functions exist, should I write my own, or am I missing the point?

查看:111
本文介绍了替代在R系统()调用SED,rsync的,SSH等:做功能存在,我应该写我自己的,还是我错过了点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我发现了 ::基地文件命令。随着像 getwd write.lines file.show DIR 等,似乎有一些的bash函数R当量。

我也写在R,它将简化呼叫 SSH 的rsync 系统

例如:

  rsync的<  - 功能(从,到){
  系统(粘贴('rsync的-outi,从,到09月=''),实习生= TRUE)
}

但在此之前,我去更远这一点,我有几个问题:


  • 确实ř已经内置了对常见的shell程序命令,如果是这样,我在哪里可以找到他们呢?

  • 如果不是,是否有原因,以避免写我自己的职能?

  • 有没有在上面的的rsync 例子介绍的方法更好的选择吗?

  • 将这样的功能集合值得一包?


解决方案

  

确实ř已经内置了对常见的shell程序命令,如果
  所以,我在哪里可以找到它们?


有像的grep 模仿贝壳progams一些功能。寻找他们,你会任何其他职能及ndash的;名称往往是相同


  

如果不是,是否有原因,以避免写我自己的职能?


没有明显的问题。


  

有没有办法一个更好的选择在rsync的概述
  上面的例子?


看起来不错,但你必须非常小心地检查用户输入,如果事情传递给shell。


  

将这样的功能集合值得一包?


当然可以。去了。

Recently, I found the base::files commands. Along with other commands like getwd, write.lines, file.show, dir, etc. there seem to be a number of R equivalents of bash functions.

I have also written some functions in R that streamline calls to ssh and rsync through system.

for example:

rsync <- function(from, to){
  system(paste('rsync -outi', from, to, sep = ' '), intern=TRUE)
}

But before I go to much further with this, I have a few questions:

  • does R already have built in commands for common shell programs, if so, where can I find them?
  • if not, are there reasons to avoid writing my own functions?
  • is there a better alternative to the approach outlined in the rsync example above?
  • would a collection of such functions warrant a package?

解决方案

does R already have built in commands for common shell programs, if so, where can I find them?

There are some function like grep that mimic shell progams. Search for them as you would any other function – the names are often the same.

if not, are there reasons to avoid writing my own functions?

No obvious problems.

is there a better alternative to the approach outlined in the rsync example above?

Looks good, but you need to be very careful about checking user input if things are passed to the shell.

would a collection of such functions warrant a package?

Absolutely. Go for it.

这篇关于替代在R系统()调用SED,rsync的,SSH等:做功能存在,我应该写我自己的,还是我错过了点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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