2.1 Brief introductiuon about R and RStudio
R is one of the most widely used programming languages for statistical modelling (Dalpiaz 2021). It has become the lingua franca of Data Science. Being open-source, R enjoys community support of avid developers who work on releasing new packages, updating R, and making it a steady and fast programming package for Data Science(Hadley Wickham 2021).
Features of R Programming
R Programming has the following features:
- R is a comprehensive programming language that provides support for procedural programming involving functions as well as object-oriented programming with generic functions.
- R can be extended easily. There are over 10,000 packages in the repository of R programming. With these packages, one can make use of extended functions to facilitate easier programming.
- Being an interpreter-based language, R produces a machine-independent code that is portable in nature. Furthermore, it facilitates easy debugging of the code.
- R supports complex operations with vectors, arrays, data frames as well as other data objects that have varying sizes.
- R can be easily integrated with many other technologies and frameworks like Hadoop and Spark. It can also integrate with other programming languages like C, C++, Python, Java, FORTRAN, and JavaScript.
- R provides robust facilities for data handling and storage. As discussed in the above section, R has extensive community support that provides technical assistance, seminars, and several boot camps to get you started with R.
- R is cross-platform compatible. R packages can be installed and used on any OS in any software environment without any changes.
R Scripts
R is the primary statistical programming language for performing modelling and graphical tasks. so it can run in the command line as an interpreting language. However, With its extensive support for performing increasingly complex computations such as manipulations on matrix and dataframe, R is now mostly running in the script for a variety of tasks that involve complex datasets with complex operations.
There is plenty of editing tools that perform interactions with the native R console. With any one of them, you can edit and run R script. You can also simply import extra packages and use the provided functions to achieve results with minimal number lines of code. There are several editors and IDEs that facilitate GUI features for authoring and executing R scripts. Some of the useful editors that support the R programming language are RGui (R Graphical User Interface) and RStudio, an integrated R script development environment.
This book will NOT teach you how to code in R. Learning R and to code in R language is not so hard. It just requires a lot of trials and time-spending. You can always go online and searching on Google, Baidu, or StackOverflow (https://stackoverflow.com/). There are also plenty of examples and codes. The chances are if you’re trying to figure out how to do something in R, other people have tried as well, so rather than banging your head against the wall, look online. There are also some books available to help you out on this front as well. I suggest looking at other people’s code and run it to see the results. R manual (https://cran.r-project.org/manuals.html) is always handy and is available.
If you want to learn R systematically, there are many sources online providing good tutorials. You can try to learn more R language from R tutorials. Tutorialspoint (http://www.tutorialspoint.com/r/index.htm), Codecademy (https://www.codecademy.com/). If you prefer an online interactive environment to learn R, this free R tutorial by DataCamp (https://www.datacamp.com/courses/free-introduction-to-r) is a great way to get started.
R Graphical User Interface (RGui)
RGui is a standard GUI (Graphic User Interface) platform that comes with an R release. By default, it provides two windows: R Console (on the left) and R Editor (on the right). See: Figure 2.1
R Console is an essential part of the RGui. In this window, we input various instructions, commands, and scripts for different operations. The results of any operation or instruction execution are displayed at the console window including warning and error messages. Console window utilizes several other useful tools embedded to facilitate and ease various operations. The console window appears whenever you access the RGui.
R Editor is a simple built-in text editor. Where you can create a new R script, edit, test, and debug the script and save it into a file. To lunch R Editor, in the main panel of RGui, go to the “File
” menu and select the “New Script
” option. This will lunch R Editor and allow you to create a new script in R. R Editor has a function of “Run line or selection
”. It means you can debug your code by line or selection. It is a very convenient tool for debugging.
RStudio
RStudio (https://rstudio.com/products/rstudio/) is an integrated and comprehensive Integrated Development Environment (IDE) for R. It facilitates extensive code editing, debugging, and development. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging, and workspace management. Figure 2.2 is a screen shot of the RStudio.
Here are some distinctive features provided by the RStudio:
- An IDE that was built just for R. With Syntax highlighting, code completion, and smart indentation. It can execute R code directly from the source editor. it can quickly jump to function definitions
- Bring your workflow together. Integrated R help and documentation with easily manage multiple working directories using projects and Workspace browser and data viewer
- Powerful authoring & Debugging. Interactive debugger to diagnose and fix errors quickly and extensive package development tools can authoring with Sweave and R Markdown
RStudio is available in open source and commercial editions and runs on the desktop (Windows, Mac, and Linux) or in a browser connected to RStudio Server or RStudio Server Pro.
We will use RStudio for the whole book. The detailed RStudio IDE is explained in (https://rstudio.com/products/rstudio/).
References
Dalpiaz, David. 2021. Applied Statistics with R. otexts. http://daviddalpiaz.github.io/appliedstats/.
Hadley Wickham, Garrett Grolemund. 2021. R for Data Science. otexts. https://r4ds.had.co.nz/index.html.