Program for data analysis using R and learn practical skills to make your work more efficient. This revised book explores how to automate running code and the creation of reports to share your results, as well as writing functions and packages. It includes key R 4 features such as a new color palette for charts, an enhanced reference counting system, and normalization of matrix and array types where matrix objects now formally inherit from the array class, eliminating inconsistencies. Advanced R 4 Data Programming and the Cloud is not designed to teach advanced R programming nor to teach the theory behind statistical procedures. Rather, it is designed to be a practical guide moving beyond merely using R; it shows you how to program in R to automate tasks. This book will teach you how to manipulate data in modern R structures and includes connecting R to databases such as PostgreSQL, cloud services such as Amazon Web Services (AWS), and digital dashboards such as Shiny. Each chapter also includes a detailed bibliography with references to research articles and other resources that cover relevant conceptual and theoretical topics. What You Will Learn Write and document R functions using R 4 Make an R package and share it via GitHub or privately Add tests to R code to ensure it works as intended Use R to talk directly to databases and do complex data management Run R in the Amazon cloud Deploy a Shiny digital dashboard Generate presentation-ready tables and reports using R Who This Book Is For Working professionals, researchers, and students who are familiar with R and basic statistical techniques such as linear regression and who want to learn how to take their R coding and programming to the next level. Table of Contents 4 About the Authors 9 About the Technical Reviewer 11 Acknowledgments 12 Chapter 1: Programming Basics 13 1.1 Software Choices and Reproducibility 13 1.2 Reproducing Results 14 1.3 Types of Objects 14 1.4 Base Operators and Functions 20 1.5 Mathematical Operators and Functions 30 1.6 Summary 37 Chapter 2: Programming Utilities 39 2.1 Installing and Using Packages 39 2.2 Help and Documentation 40 2.3 System and Files 42 2.4 Input 48 2.5 Output 53 2.6 Summary 54 Chapter 3: Programming Automation 56 3.1 Loops 57 3.2 Flow Control 64 3.3 apply Family of Functions 66 3.4 Summary 74 Chapter 4: Writing Functions 76 4.1 Components of a Function 77 4.2 Scoping 78 4.3 Functions for Functions 82 4.4 Debugging 90 4.5 Summary 102 Chapter 5: Writing Classes and Methods 104 5.1 S3 System 105 S3 Classes 105 S3 Methods 112 5.2 S4 System 122 S4 Classes 123 S4 Class Inheritance 129 S4 Methods 131 5.3 Summary 136 Chapter 6: Writing Packages 139 6.1 Before You Get Started 140 Version Control 142 6.2 R Package Basics 147 Starting a Package by Using DevTools 148 Adding R Code 153 Tests 155 6.3 Documentation Using roxygen2 162 Functions 162 Data 165 Classes 167 Methods 168 6.4 Building, Installing, and Distributing an R Package 170 6.5 R Package Website 187 6.6 Summary 189 Chapter 7: Introduction to data.table 191 7.1 Introduction to data.table 191 7.2 Selecting and Subsetting Data 198 Using the First Formal 198 Using the Second Formal 202 Using the Second and Third Formals 204 7.3 Variable Renaming and Ordering 207 7.4 Creating Variables 209 7.5 Merging and Reshaping Data 215 Merging Data 215 Reshaping Data 224 7.6 Summary 229 Chapter 8: Advanced data.table 231 8.1 Data Munging/Cleaning 232 Recoding Data 234 Recoding Numeric Values 243 8.2 Creating New Variables 246 8.3 Fuzzy Matching 251 8.4 Summary 258 Chapter 9: Other Data Management Packages 260 9.1 Sorting 262 9.2 Selecting and Subsetting 265 9.3 Variable Renaming and Ordering 275 9.4 Computing on Data and Creating Variables 277 9.5 Merging and Reshaping Data 282 9.6 Summary 288 Chapter 10: Reading Big Data 290 10.1 Installing PostgreSQL on Windows 291 10.2 Interfacing R and PostgreSQL 292 10.3 Database Philosophy 295 10.4 Adding Data to PostgreSQL 296 10.5 Creating Users with Specific Privilege 299 10.6 Password Security 308 10.7 SQL from R 310 10.8 Summary 316 Chapter 11: Getting Your Cloud 318 11.1 Disclaimers 319 11.2 Starting Amazon Web Services 319 11.3 Launching an EC2 Instance 324 11.4 Accessing Your Instance’s Command Line 327 11.5 Uploading Files to Your Instance 331 11.6 Summary 334 Chapter 12: Cloud Ubuntu for Windows Users 335 12.1 Getting Started 335 12.2 Common Commands 336 12.3 Super User and Security 340 12.4 Installing and Using R 343 Using R 346 12.5 Installing and Using RStudio Server 349 12.6 Installing Java 355 12.7 Installing Shiny on Your Cloud 355 12.8 PostgreSQL 358 12.9 Summary 362 Chapter 13: Every Cloud Has a Shiny Lining 364 13.1 The Basics of Shiny 365 13.2 Shiny in Motion 374 13.3 Uploading a User File into Shiny 376 13.4 Hosting Shiny in the Cloud 381 13.5 Summary 382 Chapter 14: Shiny Dashboard Sampler 384 14.1 A Dashboard’s Bones 384 Dashboard Header 387 Dashboard Sidebar 388 Dashboard Body 391 14.2 Dashboard in the Cloud 395 14.3 Complete Sampler Code 397 14.4 Summary 402 Chapter 15: Dynamic Reports 404 15.1 Needed Software 405 Local Machine 405 LaTeX Product 405 Cloud Instance 406 15.2 Dynamic Documents 407 15.3 Dynamic Documents and Shiny 411 server.R 411 ui.R 416 report.Rmd 419 15.4 Uploading to the Cloud 425 15.5 Summary 425 Bibliography 428 Index 431 Program for data analysis using R and learn practical skills to make your work more efficient. This revised book explores how to automate running code and the creation of reports to share your results, as well as writing functions and packages. It includes key R 4 features such as a new color palette for charts, an enhanced reference counting system, and normalization of matrix and array types where matrix objects now formally inherit from the array class, eliminating inconsistencies. __Advanced R 4 Data Programming and the Cloud__ is not designed to teach advanced R programming nor to teach the theory behind statistical procedures. Rather, it is designed to be a practical guide moving beyond merely using R; it shows you how to program in R to automate tasks. This book will teach you how to manipulate data in modern R structures and includes connecting R to databases such as PostgreSQL, cloud services such as Amazon Web Services (AWS), and digital dashboards such as Shiny. Each chapter also includes a detailed bibliography with references to research articles and other resources that cover relevant conceptual and theoretical topics.**What You Will Learn*** Write and document R functions using R 4 * Make an R package and share it via GitHub or privately * Add tests to R code to ensure it works as intended * Use R to talk directly to databases and do complex data management * Run R in the Amazon cloud * Deploy a Shiny digital dashboard * Generate presentation-ready tables and reports using R Working professionals, researchers, and students who are familiar with R and basic statistical techniques such as linear regression and who want to learn how to take their R coding and programming to the next level.