The R programming language is basically command-line (interpreter-type) programming. We can perform any type of mathematical and statistical calculation, including data management analysis and graphics in the command line. The R
command window is known as the R console, where the command and the results are produced upon execution of a given command.
Here is a very basic example of using the R console:
> (44/55)*100 [1] 80 > log(25) [1] 3.218876 > log10(25) [1] 1.39794 > exp(0.23) [1] 1.2586 > 453/365.25 [1] 1.240246 > 1-5*0.2 [1] 0 > 1-0.2-0.2-0.2-0.2-0.2 # An interesting calculation [1] 5.551115e-17
Using the R console, we can perform any type of calculation, but we always need to preserve the code to reproduce the result of any scientific analysis. From this perspective, the R console is not user-friendly when it comes to saving commands. To save the necessary commands for future use and to ensure reproducibility of research results, R has a command editor, which is known as the script editor. The script editor is just like a plain text editor. We can preserve code and comments in R
script files. The R console allows only one line of command at a time, and it executes as soon as we enter. However, in the script file, we can run a batch of code at a time. To write any type of comment related to any analysis in R, we can place a #
(hash) sign as the starting character. Here is an example:
# This is a comment line