bash 我可以在 R 会话中调用 linux shell 命令吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17423106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I invoke linux shell commands in a R session?
提问by zeno tsang
I am using RStudio and at times I want to remove some files in the working directory (e.g., previously generated .csv files).
我正在使用 RStudio,有时我想删除工作目录中的一些文件(例如,以前生成的 .csv 文件)。
It is quite inconvenient to frequently switch to bash and execute rm. Is there any way of invoking commands in the R console?
频繁切换到 bash 并执行 非常不方便rm。有没有办法在 R 控制台中调用命令?
回答by doctorlove
回答by CnrL
If you are just removing files, rather than executing arbitrary commands on the shell, you would be better off following Thomas's suggestion:
如果您只是删除文件,而不是在 shell 上执行任意命令,那么您最好遵循 Thomas 的建议:
?file.remove
Using this function instead of shell("rm example.csv")is safer and more portable.
使用此功能代替shell("rm example.csv")更安全,更便携。

