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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:49:28  来源:igfitidea点击:

Can I invoke linux shell commands in a R session?

rbash

提问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

See hereUse system (or shell) as agstudy's comment says

请参阅此处使用系统(或外壳)作为 agstudy 的评论说

e.g. system("pwd")

例如 system("pwd")

回答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")更安全,更便携。