You are previewing Mastering RStudio – Develop, Communicate, and Collaborate with R.
O'Reilly logo
Mastering RStudio – Develop, Communicate, and Collaborate with R

Book Description

Harness the power of RStudio to create web applications, R packages, markdown reports and pretty data visualizations

About This Book

  • Discover the multi-functional use of RStudio to support your daily work with R code

  • Learn to create stunning, meaningful, and interactive graphs and learn to embed them into easy communicable reports using multiple R packages

  • Develop your own R packages and Shiny web apps to share your knowledge and collaborate with others.

  • Who This Book Is For

    This book is aimed at R developers and analysts who wish to do R statistical development while taking advantage of RStudio’s functionality to ease their development efforts. R programming experience is assumed as well as being comfortable with R’s basic structures and a number of functions.

    What You Will Learn

  • Discover the RStudio IDE and details about the user interface

  • Communicate your insights with R Markdown in static and interactive ways

  • Learn how to use different graphic systems to visualize your data

  • Build interactive web applications with the Shiny framework to present and share your results

  • Understand the process of package development and assemble your own R packages

  • Easily collaborate with other people on your projects by using Git and GitHub

  • Manage the R environment for your organization with RStudio and Shiny server

  • Apply your obtained knowledge about RStudio and R development to create a real-world dashboard solution

  • In Detail

    RStudio helps you to manage small to large projects by giving you a multi-functional integrated development environment, combined with the power and flexibility of the R programming language, which is becoming the bridge language of data science for developers and analyst worldwide. Mastering the use of RStudio will help you to solve real-world data problems.

    This book begins by guiding you through the installation of RStudio and explaining the user interface step by step. From there, the next logical step is to use this knowledge to improve your data analysis workflow. We will do this by building up our toolbox to create interactive reports and graphs or even web applications with Shiny. To collaborate with others, we will explore how to use Git and GitHub with RStudio and how to build your own packages to ensure top quality results. Finally, we put it all together in an interactive dashboard written with R.

    Style and approach

    An easy-to-follow guide full of hands-on examples to master RStudio.

    Beginning from explaining the basics, each topic is explained with a lot of details for every feature.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Mastering RStudio – Develop, Communicate, and Collaborate with R
      1. Table of Contents
      2. Mastering RStudio – Develop, Communicate, and Collaborate with R
      3. Credits
      4. About the Authors
      5. About the Reviewer
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Errata
          2. Piracy
          3. Questions
      8. 1. The RStudio IDE – an Overview
        1. Downloading and installing RStudio
          1. Installing R
          2. For Ubuntu
          3. Using RStudio with different versions of R
            1. Windows
            2. Ubuntu
          4. Updating RStudio
          5. Getting to know the RStudio interface
          6. The four main panes
          7. The Source editor pane
          8. Syntax highlighting
            1. Code completion
            2. Executing R Code from the source pane
            3. Code folding
            4. Debugging code
          9. The Environment and History panes
            1. History pane
          10. Console pane
          11. The Files, Plots, Packages, Help, and Viewer panes
            1. The Files pane
            2. The Plot pane
            3. The Packages pane
            4. The Help pane
            5. The Viewer pane
          12. Customizing RStudio
          13. Using keyboard shortcuts
        2. Working with RStudio and projects
          1. Creating a project with RStudio
          2. Locating your project
          3. Using RStudio with Dropbox
            1. Preventing Dropbox synchronization conflicts
          4. Creating your first project
            1. Organizing your folders
            2. Saving the data
            3. Analyzing the data
            4. Correcting the path for report exporting
            5. Exporting your analysis as a report
        3. Summary
      9. 2. Communicating Your Work with R Markdown
        1. The concept of reproducible research
        2. Doing reproducible research with R Markdown
          1. What is Markdown?
          2. What is literate programming?
            1. A brief side note on Sweave
            2. Dynamic report generation with knitr
          3. What is R Markdown?
            1. A side note about LaTeX
            2. Configuring R Markdown
        3. Getting started with R Markdown in RStudio
          1. Creating your first R Markdown document
        4. The R Markdown interface
          1. Inspecting the R Markdowns panes
          2. Explaining the R Markdown File pane settings
            1. File tab arrows
            2. Saving current document
            3. Spell check
            4. Find/replace
            5. Question mark
            6. Knit HTML
            7. Gear icon
              1. Output Format: HTML
              2. Output Format – PDF
              3. Output Format – Word
            8. Run and re-run icons
            9. Chunks
            10. Jump to menu
            11. Viewer pane options
        5. Advanced R Markdown documents
          1. Getting to know R code chunks
          2. Customizing R code chunks
            1. Chunk options
              1. Avoiding errors, warnings, and other messages
              2. Hiding distracting lines of code
            2. Embedding R code inline
            3. Labeling code chunks
          3. Pandoc and knitr options
            1. Output formats
            2. Changing the look of the output
            3. Using a custom CSS style sheet
          4. Using R Markdown templates
            1. Package vignette
            2. The Tufte handout
          5. Compiling R Notebooks
          6. Generating R Markdown presentations
            1. ioslides
            2. Slidy
            3. Beamer
        6. Summary
      10. 3. R Lesson I – Graphics System
        1. The graphic system in R
          1. An introduction to the graphic devices
        2. The R graphics package—base
          1. Creating base plots
            1. Using the base graphics
            2. Base graphics parameters
            3. Annotating with base plotting functions
        3. Introducing the lattice package
          1. Creating lattice plots
          2. Getting to know the lattice plot types
          3. The lattice panel functions
          4. Lattice key points summary
        4. Introducing ggplot2
          1. Looking at the history of ggplot2
          2. The Grammar of Graphics
        5. Applying The Grammar of Graphics with ggplot2
        6. Using ggplot2
          1. Installing the ggplot2 package
          2. Qplot() and ggplot()
          3. Creating your first graph with ggplot2
            1. Modifying ggplot objects with the plus operator
          4. Setting the aesthetics parameter
          5. Adding layers using geoms
            1. Choosing the right geom
          6. Modifying parameters
            1. Changing the color of your plot
            2. Changing the shape
            3. Changing the size
            4. Saving ggplot objects in variables
          7. Using stats layers
          8. Saving ggplot graphs
        7. Customizing your charts
          1. Subsetting your data
          2. Setting titles
          3. Changing the axis labels
          4. Swapping the X and Y axes
          5. Improving the look of ggplot2 charts
            1. Creating graphs with the economist theme
            2. Creating graphs with the wall street journal theme
        8. Interactive plotting systems
          1. Introducing ggvis
            1. Our first ggvis graphic
            2. Interactive ggvis graphs
          2. A look at the rCharts package
          3. Using googleVis
          4. HTML widgets
            1. dygraphs
            2. Leaflet
            3. rbokeh
        9. Summary
      11. 4. Shiny – a Web-app Framework for R
        1. Introducing Shiny – the app framework
          1. Creating a new Shiny web app with RStudio
          2. Creating your first Shiny application
            1. Sketching the final app
            2. Constructing the user interface for your app
            3. Creating the server file
            4. The final application
          3. Deconstructing the final app into its components
            1. The components of the user interface
            2. The server file in detail
          4. The connection between the server and the ui file
        2. The concept of reactivity
          1. The source and endpoint structure
          2. The purpose of the reactive conductor
        3. Discovering the scope of the Shiny user interface
          1. Exploring the Shiny interface layouts
            1. The sidebar layout
            2. The grid layout
            3. The tabset panel layout
            4. The navlist panel layout
            5. The navbar page as the page layout
          2. Adding widgets to your application
            1. Shiny input elements
            2. A brief overview of the output elements
            3. Individualizing your app even further with Shiny tags
          3. Creating dynamic user interface elements
            1. Using conditionalPanel
            2. Taking advantage of the renderUI function
        4. Sharing your Shiny application with others
          1. Offering a download of your Shiny app
            1. Gist
            2. GitHub
            3. Zip file
            4. Package
          2. Deploying your app to the web
            1. Shinyapps.io
            2. Setting up a self-hosted Shiny server
        5. Diving into the Shiny ecosystem
          1. Creating apps with more files
          2. Expanding the Shiny package
        6. Summary
      12. 5. Interactive Documents with R Markdown
        1. Creating interactive documents with R Markdown
        2. Using R Markdown and Shiny
          1. Shiny Document
          2. Shiny Presentation
          3. Disassembling a Shiny R Markdown document
        3. Embedding interactive charts into R Markdown
          1. Using ggvis for interactive R Markdown documents
          2. rCharts
          3. googleVis
          4. HTML widgets
          5. dygraphs
            1. Three.js and R
            2. networkD3
            3. metricsgraphics
        4. Publishing interactive R Markdown documents
        5. Summary
      13. 6. Creating Professional Dashboards with R and Shiny
        1. Explaining the concept of dashboards
        2. Introducing the shinydashboard package
          1. Installing shinydashboard
          2. Explaining the structure of shinydashboard
        3. Showing the elements of shinydashboard
          1. Header elements
          2. Sidebar elements
          3. Body elements
            1. Boxes
            2. FluidRows
          4. InfoBox and valueBox
        4. Building your own KPI dashboard
          1. Creating our data architecture
          2. Sketching the look of our dashboard
          3. Transferring our plan into R code
            1. Considering a file and folder structure
            2. Accessing our data sources
              1. MySQL – the customer data
              2. Dropbox – our data storage system
              3. Google Analytics – the website data
              4. Twitter – the social data
              5. Google Sheets – the inventory data
            3. Putting it all together
              1. Creating the Twitter engagement box
        5. Summary
      14. 7. Package Development in RStudio
        1. Understanding R packages
          1. Understanding the package structure
        2. Installing devtools
        3. Building packages with RStudio
          1. Creating a new package project with RStudio
          2. Looking at the created files
        4. Using Packrat with a project
        5. Writing the documentation for a package
          1. Creating Rd documentation files
          2. Looking at an example documentation file
          3. Adding examples
            1. dontrun
            2. dontshow
          4. Editing the DESCRIPTION file
            1. General information
            2. Dependencies
            3. License
        6. Understanding the namespaces of a package
        7. Building and checking a package
          1. Checking a package
          2. Customizing the package build options
        8. Using roxygen2 for package documentation
          1. Installing the roxygen2 package
          2. Generating Rd Files
        9. Testing a package
          1. Using testthat in a package
        10. Adding a dataset to a package
          1. Creating .rda files
          2. Using LazyData with a package
        11. Writing a package vignette with R markdown
          1. Creating vignette files
        12. References for further information
        13. Summary
      15. 8. Collaborating with Git and GitHub
        1. Introducing version control
          1. Installing Git
            1. Installing Git on Windows
            2. Installing Git on Linux
          2. Configuring Git
          3. Explaining the basic terminology
            1. Repository
            2. Commit
            3. Diff
            4. Branch
            5. Merge
            6. Fetch
            7. Pull
            8. Push
          4. Using Git via shell
          5. Using the shell from Rstudio
        2. Using Git with RStudio
          1. Using RStudio and GitHub via SSH
          2. Creating a new project with Git
            1. Explaining the gitignore file
          3. Keeping track of changes
          4. Recording changes
          5. Introducing the Git drop-down menu
          6. Undoing a mistake
          7. Pushing to a remote repository on github.com
          8. Using an existing GitHub project with RStudio
        3. Using branches
          1. Making a pull request
          2. Reviewing and merging pull requests
        4. Further resources
        5. Summary
      16. 9. R for your Organization – Managing the RStudio Server
        1. Managing the RStudio Server
          1. Using Amazon Web Services as the server platform
          2. Creating an AWS account
          3. Using S3 to store our data
            1. Creating our bucket
            2. Uploading a dataset to the bucket
          4. Launching our EC2 instance
            1. Choosing An amazon Machine Image
            2. Choosing an instance type
            3. Configuring instance details
              1. Creating a new IAM role
            4. Adding storage
            5. Tagging an instance
            6. Configuring a security group
            7. Reviewing
              1. Creating a key pair
              2. Launching the instance
          5. Connecting with the new EC2 instance
            1. What is SSH?
            2. Bringing it all together
        2. Setting up R, RStudio, and the Shiny Server
          1. Choosing your RStudio version
          2. Installing base R
          3. Installing RStudio and the Shiny Server
            1. RStudio and the Shiny Server in your browser
          4. Administrating your RStudio server environment
            1. Getting rid of the R memory problem
            2. Connecting our S3 bucket with RStudio
            3. Basic RStudio server management
          5. Managing the Shiny Server
            1. Basic commands for the Shiny Server
        3. Summary
      17. 10. Extending RStudio and Your Knowledge of R
        1. Extending RStudio, finding answers, and more
        2. RStudio environment customizations
          1. Customizing the Rprofile
            1. Where to find your Rprofile
            2. Adding custom functions
              1. The first and last functions
              2. More ideas for your Rprofile
        3. R help is on the way
          1. Getting questions and answers
            1. Stack Overflow (Stack Exchange)
            2. Data Science (Stack Exchange)
            3. Cross Validated (Stack Exchange)
            4. Open Data (Stack Exchange)
            5. R mailing lists – R-help
            6. Reddit
            7. How to ask questions correctly
          2. Learning more about packages, functions, and more
            1. R FAQs
            2. R and CRAN documentations
            3. R search engines
            4. RStudio cheat sheets
            5. Sharing your R code
        4. Improving your R knowledge
          1. Learning R interactively
            1. Try R
            2. DataCamp
            3. Leada
            4. Swirl
          2. Attending online courses
            1. Coursera
              1. Johns Hopkins University – Data Science Specialization
              2. Johns Hopkins University – Genomic Data Science
            2. Udacity
            3. Other MOOC courses, related platforms, and programs
        5. Staying up to date in the R world
          1. R-Bloggers
          2. The R Journal
        6. Summary
      18. Index