Member-only story

How To Run R Programs In Terminal / Command Prompt On Windows / MacOS!

Manpreet Singh
2 min readJan 14, 2021

--

R is an awesome language for data processing, but it can be annoying sometimes to constantly go into RStudio to run the code we made, but instead of doing that, we can run the code in our Terminal / Command Prompt! The process is extremely easy, here is exactly how to do that!

First off, make sure you have R installed on your machine, if you don’t, here is an article I made on exactly how to do that! Now let’s get started!

First off, let’s locate the R file that we want to run, if you don’t have any R files to run, go ahead and open up your IDE or Text editor and type in “print(“Hello”)” in the file and save it as a .R file!

Now save the file “test.R” or any other name you want. At this point, you want to copy the directory of the file, on most machines you can just copy the file but I would recommend looking up how to do so on your OS. At this point, make your way over to your command prompt / terminal. To run a R file in this box you’ll have to start off the code with “rscript”, then you have to paste that directory right after on the same line, so it should look something like this:

At this point, go ahead and click enter and voila! You will see that the R program has ran and the output will show in the terminal / command prompt!

Have fun running R programs on your OS!

--

--

Manpreet Singh
Manpreet Singh

No responses yet