2

I am using RStudio and at times I want to remove some files in the working directory (e.g., previously generated .csv files).

It is quite inconvenient to frequently switch to bash and execute rm. Is there any way of invoking commands in the R console?

lmo
  • 37,904
  • 9
  • 56
  • 69
zeno tsang
  • 735
  • 1
  • 6
  • 16

2 Answers2

6

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

e.g. system("pwd")

doctorlove
  • 18,872
  • 2
  • 46
  • 62
6

If you are just removing files, rather than executing arbitrary commands on the shell, you would be better off following Thomas's suggestion:

?file.remove

Using this function instead of shell("rm example.csv") is safer and more portable.

CnrL
  • 2,558
  • 21
  • 28