R is an interpreted language so your R code is directly executed instead of being compiled into an object language. R is different from SAS in that there are five different essential R data objects and structures – vectors, matrix, array, data frames and lists. For SAS programmers, vectors and data frames are the most important. As a basic concept, vectors are similar to values in a dataset with only one variable and data frames contain a collection of vectors so contain many variables and records. Most all R processing is performed on data frames. All R data structures and any outputs created from R functions are R objects.
Within RStudio, submitting R commands is a simple process. Once an R script file is opened, you just select one or more lines and enter Control-Enter to execute them. The alternative is to select Code from the menu and then Run Line or Selection or Run All. The cursor can be placed anywhere on the R command to execute it. Note that if partial R command is submitted, then R will insert ‘+’ in the log to recognize partial R commands and will then expect the remaining R command. See the log window for results after each R comment.
The R script is essentially a text file with an .R extension. The .R extension enables R to recognize it. A tip is to copy R comments from a text file into an R script file. First set the folder to your R program, setwd('/home/username/desktop/rcode') and then enter source('analyze.r'). Best practices are to create an R setup file to install packages and load libraries used on regular tasks similar to SASAUTOS.
Within base R, you can run R statements individually from the Edit > Run Line or Selection option or run all R statements in an R script file from the Edit > Run All option. Results will be displayed in the console window and the tg data frame window will open.
For maximum viewing of R program and log, select Windows > Tile Horizontally.