How To Run Python Files In R
R & Python are amazing languages for data processing / data engineering, however, there are certain things that Python can do that R can’t necessarily do (and vice versa). This includes packages included in Python that R doesn’t necessarily have. I’ll go ahead and show you exactly how to run python scripts inside of R.
To Get started, make sure you have both R and Python installed on your machine, if you don’t have them installed I have written articles on exactly how to do that (Python article here, R article here). Once installed, we want to go ahead and open up our R script, so make your way to RStudio (or other IDE), and create a new blank R script, your page will look like this:
Now, we want to go ahead and install a new package, this package is called reticulate. So we want to go down to our R console and type in install.packages(“reticulate)
Once you run that line we can now start running our python scripts! To get started, let’s go ahead and make a sample Python file, open up any text editor and type in “print(“hello”)”, just like this: