Home Page Icon
Home Page
Table of Contents for
Section IV - Performance
Close
Section IV - Performance
by Hadley Wickham
Advanced R
Preliminaries
Dedication
Chapman & Hall/CRC: The R Series
Chapter 1 - Introduction
1.1 Who should read this book
1.2 What you will get out of this book
1.3 Meta-techniques
1.4 Recommended reading
1.5 Getting help
1.6 Acknowledgments
1.7 Conventions
1.8 Colophon
Section I - Foundations
Chapter 2 - Data structures
Quiz
Quiz
Outline
2.1 Vectors
2.1.1 Atomic vectors
2.1.1.1 Types and tests
2.1.1.2 Coercion
2.1.2 Lists
2.1.3 Exercises
2.2 Attributes
2.2.0.1 Names
2.2.0.1 Names
2.2.1 Factors
2.2.2 Exercises
2.3 Matrices and arrays
2.3.1 Exercises
2.4 Data frames
2.4.1 Creation
2.4.2 Testing and coercion
2.4.3 Combining data frames
2.4.4 Special columns
2.4.5 Exercises
2.5 Answers
Chapter 3 - Subsetting
Quiz
Quiz
Quiz
Outline
3.1 Data types
3.1.1 Atomic vectors
3.1.2 Lists
3.1.3 Matrices and arrays
3.1.4 Data frames
3.1.5 S3 objects
3.1.6 S4 objects
3.1.7 Exercises
3.2 Subsetting operators
3.2.1 Simplifying vs. preserving subsetting
3.2.2 $
3.2.3 Missing/out of bounds indices
3.2.4 Exercises
3.3 Subsetting and assignment
3.4 Applications
3.4.1 Lookup tables (character subsetting)
3.4.2 Matching and merging by hand (integer subsetting)
3.4.3 Random samples/bootstrap (integer subsetting)
3.4.4 Ordering (integer subsetting)
3.4.5 Expanding aggregated counts (integer subsetting)
3.4.6 Removing columns from data frames (character subsetting)
3.4.7 Selecting rows based on a condition (logical subsetting)
3.4.8 Boolean algebra vs. sets (logical & integer subsetting)
3.4.9 Exercises
3.5 Answers
Chapter 4 - Vocabulary
4.1 The basics
4.2 Common data structures
4.3 Statistics
4.4 Working with R
4.5 I/O
Chapter 5 - Style guide
5.1 Notation and naming
5.1.1 File names
5.1.2 Object names
5.2 Syntax
5.2.1 Spacing
5.2.2 Curly braces
5.2.3 Line length
5.2.4 Indentation
5.2.5 Assignment
5.3 Organisation
5.3.1 Commenting guidelines
Chapter 6 - Functions
Quiz
Quiz
Quiz
Outline
Prerequisites
6.1 Function components
6.1.1 Primitive functions
6.1.2 Exercises
6.2 Lexical scoping
6.2.1 Name masking
6.2.2 Functions vs. variables
6.2.3 A fresh start
6.2.4 Dynamic lookup
6.2.5 Exercises
6.3 Every operation is a function call
6.4 Function arguments
6.4.1 Calling functions
6.4.2 Calling a function given a list of arguments
6.4.3 Default and missing arguments
6.4.4 Lazy evaluation
6.4.5 . . .
6.4.6 Exercises
6.5 Special calls
6.5.1 Infix functions
6.5.2 Replacement functions
6.5.3 Exercises
6.6 Return values
6.6.1 On exit
6.6.2 Exercises
6.7 Quiz answers
Chapter 7 - OO field guide
Prerequisites
Prerequisites
Prerequisites
Quiz
Outline
7.1 Base types
7.2 S3
7.2.1 Recognising objects, generic functions, and methods
7.2.2 Defining classes and creating objects
7.2.3 Creating new methods and generics
7.2.4 Method dispatch
7.2.5 Exercises
7.3 S4
7.3.1 Recognising objects, generic functions, and methods
7.3.2 Defining classes and creating objects
7.3.3 Creating new methods and generics
7.3.4 Method dispatch
7.3.5 Exercises
7.4 RC
7.4.1 Defining classes and creating objects
7.4.2 Recognising objects and methods
7.4.3 Method dispatch
7.4.4 Exercises
7.5 Picking a system
7.6 Quiz answers
Chapter 8 - Environments
Quiz
Quiz
Quiz
Outline
Prerequisites
8.1 Environment basics
8.1.1 Exercises
8.2 Recursing over environments
8.2.1 Exercises
8.3 Function environments
8.3.1 The enclosing environment
8.3.2 Binding environments
8.3.3 Execution environments
8.3.4 Calling environments
8.3.5 Exercises
8.4 Binding names to values
8.4.1 Exercises
8.5 Explicit environments
8.5.1 Avoiding copies
8.5.2 Package state
8.5.3 As a hashmap
8.6 Quiz answers
Chapter 9 - Debugging, condition handling, and defensive programming
Quiz
Quiz
Quiz
Outline
9.1 Debugging techniques
9.2 Debugging tools
9.2.1 Determining the sequence of calls
9.2.2 Browsing on error
9.2.3 Browsing arbitrary code
9.2.4 The call stack: traceback(), where, and recover()
9.2.5 Other types of failure
9.3 Condition handling
9.3.1 Ignore errors with try
9.3.2 Handle conditions with tryCatch()
9.3.3 withCallingHandlers()
9.3.4 Custom signal classes
9.3.5 Exercises
9.4 Defensive programming
9.4.1 Exercises
9.5 Quiz answers
Section II - Functional programming
Chapter 10 - Functional programming
Outline
Outline
Outline
Prequisites
10.1 Motivation
10.2 Anonymous functions
10.2.1 Exercises
10.3 Closures
10.3.1 Function factories
10.3.2 Mutable state
10.3.3 Exercises
10.4 Lists of functions
10.4.1 Moving lists of functions to the global environment
10.4.2 Exercises
10.5 Case study: numerical integration
10.5.1 Exercises
Chapter 11 - Functionals
Outline
Outline
Outline
Prerequisites
11.1 My first functional: lapply()
11.1.1 Looping patterns
11.1.2 Exercises
11.2 For loop functionals: friends of lapply()
11.2.1 Vector output: sapply and vapply
11.2.2 Multiple inputs: Map (and mapply)
11.2.3 Rolling computations
11.2.4 Parallelisation
11.2.5 Exercises
11.3 Manipulating matrices and data frames
11.3.1 Matrix and array operations
11.3.2 Group apply
11.3.3 The plyr package
11.3.4 Exercises
11.4 Manipulating lists
11.4.1 Reduce()
11.4.2 Predicate functionals
11.4.3 Exercises
11.5 Mathematical functionals
11.5.1 Exercises
11.6 Loops that should be left as is
11.6.1 Modifying in place
11.6.2 Recursive relationships
11.6.3 While loops
11.7 A family of functions
11.7.1 Exercises
Chapter 12 - Function operators
Outline
Outline
Outline
Prerequisites
12.1 Behavioural FOs
12.1.1 Memoisation
12.1.2 Capturing function invocations
12.1.3 Laziness
12.1.4 Exercises
12.2 Output FOs
12.2.1 Minor modifications
12.2.2 Changing what a function does
12.2.3 Exercises
12.3 Input FOs
12.3.1 Prefilling function arguments: partial function application
12.3.2 Changing input types
12.3.3 Exercises
12.4 Combining FOs
12.4.1 Function composition
12.4.2 Logical predicates and boolean algebra
12.4.3 Exercises
Section III - Computing on the language
Chapter 13 - Non-standard evaluation
Outline
Outline
Outline
Prerequisites
13.1 Capturing expressions
13.1.1 Exercises
13.2 Non-standard evaluation in subset
13.2.1 Exercises
13.3 Scoping issues
13.3.1 Exercises
13.4 Calling from another function
13.4.1 Exercises
13.5 Substitute
13.5.1 Adding an escape hatch to substitute
13.5.2 Capturing unevaluated . . .
13.5.3 Exercises
13.6 The downsides of non-standard evaluation
13.6.1 Exercises
Chapter 14 - Expressions
Outline
Outline
Outline
Prerequisites
14.1 Structure of expressions
14.1.1 Exercises
14.2 Names
14.2.1 Exercises
14.3 Calls
14.3.1 Modifying a call
14.3.2 Creating a call from its components
14.3.3 Exercises
14.4 Capturing the current call
14.4.1 Exercises
14.5 Pairlists
14.5.1 Exercises
14.6 Parsing and deparsing
14.6.1 Exercises
14.7 Walking the AST with recursive functions
14.7.1 Finding F and T
14.7.2 Finding all variables created by assignment
14.7.3 Modifying the call tree
14.7.4 Exercises
Chapter 15 - Domain specific languages
Prerequisites
Prerequisites
Prerequisites
15.1 HTML
15.1.1 Goal
15.1.2 Escaping
15.1.3 Basic tag functions
15.1.4 Tag functions
15.1.5 Processing all tags
15.1.6 Exercises
15.2 LaTeX
15.2.1 LaTeX mathematics
15.2.2 Goal
15.2.3 to_math
15.2.4 Known symbols
15.2.5 Unknown symbols
15.2.6 Known functions
15.2.7 Unknown functions
15.2.8 Exercises
Section IV - Performance
Chapter 16 - Performance
16.1 Why is R slow?
16.2 Microbenchmarking
16.2.1 Exercises
16.3 Language performance
16.3.1 Extreme dynamism
16.3.2 Name lookup with mutable environments
16.3.3 Lazy evaluation overhead
16.3.4 Exercises
16.4 Implementation performance
16.4.1 Extracting a single value from a data frame
16.4.2 ifelse(), pmin(), and pmax()
16.4.3 Exercises
16.5 Alternative R implementations
Chapter 17 - Optimising code
Outline
Outline
Outline
Prerequisites
17.1 Measuring performance
17.1.1 Limitations
17.2 Improving performance
17.3 Code organisation
17.4 Has someone already solved the problem?
17.4.1 Exercises
17.5 Do as little as possible
17.5.1 Exercises
17.6 Vectorise
17.6.1 Exercises
17.7 Avoid copies
17.8 Byte code compilation
17.9 Case study: t-test
17.10 Parallelise
17.11 Other techniques
Chapter 18 - Memory
Outline
Outline
Outline
Prerequisites
Sources
18.1 Object size
18.1.1 Exercises
18.2 Memory usage and garbage collection
18.3 Memory profiling with lineprof
18.3.1 Exercises
18.4 Modification in place
18.4.1 Loops
18.4.2 Exercises
Chapter 19 - High performance functions with Rcpp
Outline
Outline
Outline
19.1 Getting started with C++
19.1.1 No inputs, scalar output
19.1.2 Scalar input, scalar output
19.1.3 Vector input, scalar output
19.1.4 Vector input, vector output
19.1.5 Matrix input, vector output
19.1.6 Using sourceCpp
19.1.7 Exercises
19.2 Attributes and other classes
19.2.1 Lists and data frames
19.2.2 Functions
19.2.3 Other types
19.3 Missing values
19.3.1 Scalars
19.3.1.1 Integers
19.3.1.2 Doubles
19.3.2 Strings
19.3.3 Boolean
19.3.4 Vectors
19.3.5 Exercises
19.4 Rcpp sugar
19.4.1 Arithmetic and logical operators
19.4.2 Logical summary functions
19.4.3 Vector views
19.4.4 Other useful functions
19.5 The STL
19.5.1 Using iterators
19.5.2 Algorithms
19.5.3 Data structures
19.5.4 Vectors
19.5.5 Sets
19.5.6 Map
19.5.7 Exercises
19.6 Case studies
19.6.1 Gibbs sampler
19.6.2 R vectorisation vs. C++ vectorisation
19.7 Using Rcpp in a package
19.8 Learning more
19.9 Acknowledgments
Chapter 20 - R's C interface
Outline
Outline
Outline
Prerequisites
20.1 Calling C functions from R
20.2 C data structures
20.3 Creating and modifying vectors
20.3.1 Creating vectors and garbage collection
20.3.2 Missing and non-finite values
20.3.3 Accessing vector data
20.3.4 Character vectors and lists
20.3.5 Modifying inputs
20.3.6 Coercing scalars
20.3.7 Long vectors
20.4 Pairlists
20.5 Input validation
20.6 Finding the C source code for a function
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Chapter 15 - Domain specific languages
Next
Next Chapter
Chapter 16 - Performance
Part IV
Performance
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset