Book Image

Learning RStudio for R Statistical Computing

Book Image

Learning RStudio for R Statistical Computing

Overview of this book

Data is coming at us faster, dirtier, and at an ever increasing rate. The necessity to handle many, complex statistical analysis projects is hitting statisticians and analysts across the globe. This book will show you how to deal with it like never before, thus providing an edge and improving productivity. "Learning RStudio for R Statistical Computing" will teach you how to quickly and efficiently create and manage statistical analysis projects, import data, develop R scripts, and generate reports and graphics. R developers will learn about package development, coding principles, and version control with RStudio. This book will help you to learn and understand RStudio features to effectively perform statistical analysis and reporting, code editing, and R development. The book starts with a quick introduction where you will learn to load data, perform simple analysis, plot a graph, and generate automatic reports. You will then be able to explore the available features for effective coding, graphical analysis, R project management, report generation, and even project management. "Learning RStudio for R Statistical Computing" is stuffed with feature-rich and easy-to-understand examples, through step-by-step instructions helping you to quickly master the most popular IDE for R development.
Table of Contents (13 chapters)

Installing RStudio


The desktop version of RStudio can be downloaded from http://www.rstudio.com/ide for Windows XP and higher, MacOS X 10.6 or higher, and several Linux flavors. The desktop version of RStudio can be installed easily by clicking on the link for your platform and following the instructions. We strongly recommend that you check www.rstudio.com once in a while for new updates. Alternatively, you can check for updates from RStudio by clicking on Help | Check for updates.

Installing RStudio Server

RStudio Server is currently only available for Linux-based systems. Before you install it you need to have R installed, as described in the previous paragraph.

  1. Go to http://www.rstudio.com/ide/download/server and follow the instructions there to download and install the RStudio server. Once RStudio is installed, you can run it by typing the following:

    sudo rstudio-server start
    
  2. To log on you need to know the server's URL. If you have installed it locally, you can access it by pointing your browser to the following path:

    http://localhost:8787
    

RStudio allows the users of your Linux system to log on with their standard password and username, so user management can be done as in Linux.

Installing R packages

One of the most attractive features of R is the abundance of freely available extension packages. The installation of R comes bundled with many important packages, but newly developed statistical methods come readily available in packages. These packages are published on the Comprehensive R Archive Network (CRAN) and can be easily installed in RStudio. To get started, we will install the knitr package, which we'll need in our first session.

One of the tabs in the bottom right-hand side of RStudio is a package panel that allows you to browse the currently installed packages. These packages can be updated by clicking on Check for Updates. RStudio will check what packages have newer versions and will give you the option to select which of these packages should be updated. Alternatively you can use the General menu's Tools | Check for Package Updates.

To install the packages click on the Packages tab in the bottom right-hand side panel. Each tab has its own menu items at the top of the panel. Click on the Install button to start the installation. The pop-up menu that appears allows you to choose either a CRAN server or a local repository. If you have Internet access, choose a mirror somewhere near you. Next, type the first letters of the package you wish to install. Here, we will install the knitr package. When typing, RStudio will show suggestions of packages with similar names. Choose knitr and hit Enter. RStudio generates the command that installs the package, copies it to the console, and executes it.

To load the package, scroll down the window with installed packages and check it. The package is now loaded.

Tip

Trying to update a package that is currently loaded may fail. The easiest solution is to close and restart RStudio and update again without the package being loaded.