Testing r code
- Author
- Cotton, Richard James
- Published
- [Place of publication not identified] : Chapman & Hall Crc, 2016.
- Physical Description
- 1 online resource
Access Online
- Contents
- Machine generated contents note: 1.Introduction -- 1.1.Interacting vs. Programming -- 1.2.Two Kinds of Testing -- 1.3.How Run-Time Testing Will Help You -- 1.4.How Development-Time Testing Will Help You -- 1.5.Summary -- 2.Run-Time Testing with assertive -- 2.1.Using Assertions -- 2.1.1.Chaining Assertions Together with Pipes -- 2.2.Using Predicates: is and has Functions -- 2.2.1.Exercise: Using Predicates and Assertions -- 2.3.The Virtual Package System -- 2.4.A Tour of the assertive Package -- 2.4.1.assertive.base -- 2.4.2.assertive.properties -- 2.4.3.assertive.types -- 2.4.4.assertive.numbers -- 2.4.5.Exercise: Examining an Object -- 2.4.6.assertive.files -- 2.4.7.Exercise: Inspecting Files and Directories -- 2.4.8.assertive.strings -- 2.4.9.assertive.matrices -- 2.4.10.Exercise: Testing Properties of Matrices -- 2.4.11.assertive.sets -- 2.4.12.assertive.models -- 2.4.13.assertive.reflection -- 2.4.14.Exercise: Explore Your R Setup -- 2.4.15.assertive.datetimes -- 2.4.16.assertive.data, assertive.data.us, and assertive.data.uk -- 2.4.17.Exercise: Checking Customer Data -- 2.4.18.assertive.code -- 2.5.Controlling Severity -- 2.6.Fail Early, Fail Often -- 2.7.Case Study: Calculating the Geometric Mean -- 2.7.1.Exercise: Calculating the Harmonic Mean -- 2.8.Alternatives -- 2.9.Summary -- 3.Development-Time Testing with testthat -- 3.1.Using Unit Tests -- 3.2.The Structure of a Unit Test -- 3.2.1.Exercise: Using expect_equal -- 3.2.2.How Equal Is Equal? -- 3.3.Testing Errors -- 3.3.1.Exercise: Using expect_error -- 3.4.Different Types of Expectation -- 3.5.Testing Warnings and Messages -- 3.5.1.Chaining Expectations Together with Pipes -- 3.5.2.Exercise: Using expect_output -- 3.5.3.Testing for Lack of Output -- 3.6.Varying the Strictness of Expectations -- 3.7.Providing Additional Information on Failure -- 3.8.Case Study: Calculating Square Roots -- 3.8.1.Exercise: Find More Tests for square_root -- 3.9.Other Expectations -- 3.9.1.Exercise: Testing the Return Type of Replicates -- 3.10.Organising Tests Using Contexts -- 3.11.Running Your Tests -- 3.12.Customizing How Test Results Are Reported -- 3.13.Alternatives -- 3.14.Summary -- 4.Writing Easily Maintainable and Testable Code -- 4.1.Don't Repeat Yourself -- 4.1.1.Case Study: Drawing Lots of Plots -- 4.1.2.Idea 1: Use Variables Rather Than Hard-Coded Values -- 4.1.3.Idea 2: For Values That You Want To Change Everywhere, Update Global Settings -- 4.1.4.Idea 3: Wrap the Contents into a Function -- 4.1.5.Exercise: Reducing Duplication -- 4.2.Keep It Simple, Stupid -- 4.2.1.Simplifying Function Interfaces -- 4.2.2.Idea 1: Pass Arguments for Advanced Functionality to Another Function -- 4.2.3.Exercise: Outsourcing Argument Checking -- 4.2.4.Idea 2: Having Wrapper Functions for Specific Use Cases -- 4.2.5.Exercise: Wrappers for Formatting Currency -- 4.2.6.Idea 3: Auto-Guessing Defaults -- 4.2.7.Exercise: Providing Better Defaults for write.csv -- 4.2.8.Idea 4: Split Functionality into Many Functions -- 4.2.9.Exercise: Decomposing the quantile Function -- 4.2.10.Cyclomatic Complexity -- 4.2.11.How to Reduce Cyclomatic Complexity -- 4.2.12.Exercise: Calculating Leap Years -- 4.3.Summary -- 5.Integrating Testing into Packages -- 5.1.How to Make an R Package -- 5.1.1.Prerequisites -- 5.1.2.The Package Directory Structure -- 5.1.3.Including Tests in Your Package -- 5.2.Case Study: The hypotenuser Package -- 5.3.Checking Packages -- 5.3.1.Exercise: Make a Package with Tests -- 5.4.Using Version Control, Online Package Hosting, and Continuous Integration -- 5.4.1.Version Control with git -- 5.4.2.Online Project Hosting -- 5.4.3.Continuous Integration Services -- 5.5.Testing Packages on CRAN -- 5.5.1.Testing Packages with r-hub -- 5.6.Calculating Test Coverage Using coveralls.io -- 5.7.Summary -- 6.Advanced Development-Time Testing -- 6.1.Code with Side Effects -- 6.1.1.Exercise: Writing a Test That Handles Side Effects -- 6.2.Testing Complex Objects -- 6.2.1.Exercise: Testing a Complex Object -- 6.3.Testing Database Connections -- 6.3.1.Option 1: Mock the Connection -- 6.3.2.Option 2: Mock the Connection Wrapper -- 6.3.3.Option 3: Mock the Specific Query Functions -- 6.3.4.Summarizing the Pros and Cons of Each Database Method -- 6.4.Testing Rcpp Code -- 6.4.1.Getting Set Up to Use C++ -- 6.4.2.Case Study: Extending the hypotenuser Package to Include C++ Code -- 6.4.3.Exercise: Testing an Rcpp Function -- 6.5.Testing Write Functions -- 6.5.1.Exercise: Writing INI Configuration Files -- 6.6.Testing Graphics -- 6.6.1.Generating the Report from the markdown -- 6.6.2.Including Graphics Tests in Packages -- 6.6.3.Exercise: Write a Graphics Test Report -- 6.7.Summary -- 7.Writing Your Own Assertions and Expectations -- 7.1.The Quick, Nearly Good Enough Option -- 7.2.Writing Scalar Predicates -- 7.2.1.Exercise: Writing a Custom Scalar Predicate -- 7.2.2.Writing Type Predicates -- 7.3.Writing Scalar Assertions -- 7.3.1.Exercise: Writing a Custom Scalar Assertion -- 7.4.Writing Vector Predicates -- 7.4.1.Exercise: Writing a Vector Predicate -- 7.5.Writing Vector Assertions -- 7.5.1.Exercise: Writing a Vector Assertion -- 7.6.Creating Custom Expectations -- 7.6.1.Exercise: Create a Custom Expectation -- 7.7.Summary -- A.Answers to Exercises -- A.1.Preface -- A.1.1.Exercise: Are You Ready? -- A.2.Chapter 2 -- A.2.1.Exercise: Using Predicates and Assertions -- A.2.2.Exercise: Examining an Object -- A.2.3.Exercise: Inspecting Files and Directories -- A.2.4.Exercise: Testing Properties of Matrices -- A.2.5.Exercise: Explore Your R Setup -- A.2.6.Exercise: Checking Customer Data -- A.2.7.Exercise: Calculating the Harmonic Mean -- A.3.Chapter 3 -- A.3.1.Exercise: Using expect_equal -- A.3.2.Exercise: Using expect_error -- A.3.3.Exercise: Using expect_output -- A.3.4.Exercise: Find More Tests for square_root -- A.3.5.Exercise: Testing the Return Type of Replicates -- A.4.Chapter 4 -- A.4.1.Exercise: Reducing duplication -- A.4.2.Exercise: Outsourcing Argument Checking -- A.4.3.Exercise: Wrappers for Formatting Currency -- A.4.4.Exercise: Providing Better Defaults for write.csv -- A.4.5.Exercise: Decomposing the quantile Function -- A.4.6.Exercise: Calculating Leap Years -- A.5.Chapter 5 -- A.5.1.Exercise: Make a Package with Tests -- A.6.Chapter 6 -- A.6.1.Exercise: Writing a Test That Handles Side Effects -- A.6.2.Exercise: Testing a Complex Object -- A.6.3.Exercise: Testing an Rcpp Function -- A.6.4.Exercise: Writing INI Configuration Files -- A.6.5.Exercise: Write a Graphics Test Report -- A.7.Chapter 7 -- A.7.1.Exercise: Writing a Custom Scalar Predicate -- A.7.2.Exercise: Writing a Custom Scalar Assertion -- A.7.3.Exercise: Writing a Vector Predicate -- A.7.4.Exercise: Writing a Vector Assertion -- A.7.5.Exercise: Create a Custom Expectation.
- ISBN
- 9781315380285 (electronic bk.)
1315380285 (electronic bk.)
View MARC record | catkey: 20268425