Two main ways you can program within RStudio

Type commands directly in the R console and press enter. The results are displayed immediately under the command. Your code is lost once you close your R session though.

OR

Start writing in an .R file (the R script file) and use RStudio’s short cut keys for running the command, i.e. sending it to the interactive console. - This is a great way to work because all your code is saved for later use as well.