For writing a program in R, you need a programming environment where you can execute your code. This programming environment is provided by RStudio. Therefore, first, you have to download and install R and RStudio from cran.r-project.org. After installation, open RStudio, and you can start writing your R code in the script editor or directly in the console.
If you are looking for an online course to learn R programming, check out this R Programming Online Course by Intellipaat.