S Programming
Preface
v
Typographical Conventions
x
1 Introduction
1.1 Versions of S
1.2 S programming .
1.3 On-line material
1
2
3
4
2 The S Language: Syntax and Semantics 5
2.1 A concise description of S objects . . . . . . . . . . 5
2.2 Arithmetical expressions . . . . . . . . . . 17
2.3 Indexing .......... . . . . . . . . . 23
2.4 Vectors, matrices and arrays . . . . . . . . 27
2.5 Character vector operations 30
2.6 Control structures. . . . . . . . . . . . 31
2.7 Vectorized calculations . . . . . . . . . 34
3 The S Language: Advanced Aspects
3.1 Functions.........
3.2 Writing functions. .
3.3 Calling the operating system . .
3.4 Databases, frames and environments. . .
3.5 Computing on the language
3.6 Graphics functions . . . . .
39
39
42
. . . . 52,
. . . . . 54
. . . . . . . . . . .. 65
. . . . . . . . 72
4 Classes 75
4.1 Introduction to classes . . . . . . . . . . . 75
4.2 An extended statistical example . . . . . . . . 83
4.3 Polynomials: an example of group method functions 87
Vl11
Contents
5 New-style Classes
5.1 Creating a class. . . . . . . .
5.2 Inheritance . . . . . . . . . .. ....
5.3 Generic and method functions . . . . . . .
5.4 Old-style classes . . . . . . .. ....
5.5 An extended statistical example revisited
5.6 Group methods and another polynomial class
99
. . . . . . . 100
. . 105
. 106
. 109
. 110
. . . . . . . . . 115
6 Using Compiled Code
6.1 Writing S functions to call compiled code.
6.2 Writing compiled code to work with S
6.3 Calling S from C . . . . . . . .
6.4 Using the . Call interface .
6.5 Debugging compiled code . . . . . .
6.6 Portability .................
123
. . 123
. . . . . . . 128
. 138
. . 141
. . 148
. . 149
7 General Strategies and Extended Examples
7.1 Managing loops ...................
7.2 A large regression .............
7.3 Simulation envelopes for normal-scores plots
7.4 Making good use of language objects . . . . .
7.5 Bootstrapping and cross-validation ......
7.6 Maximum likelihood estimates and iterative calculations
7.7 Tips............................
151
. . 153
. 159
. . . . . 161
. . . 163
. 172
. . 175
. . 177
8 S Software Development
8.1 Editing S functions and objects
8.2 Tracing and debugging . .
8.3 Creating on-line help . .
8.4 S-PLUS libraries . . . . .
8.5 R packages . . . . . . . . . . .
8.6 Developing code to be used on more than one engine . .
8.7 A checklist . . . . . . . . . . . . . . . . . . . . . .
179
. 180
. 181
. . 188
. 194
. . 200
. . . 201
. . 202
9 Interfaces under Windows
9.1 Building a dialog box. . . . . .
9.2 Adding items to the menus. . . . .
9.3 Managing a customized GUI .
205
. . 205
. . 218
. . 221
Contents
9.4 Communicating with S-PLUS: DDE ....
9.5 Communicating with S-PLUS: Automation. .
9.6 Interfacing with R .....
9.7 Some pitfalls of Automation . . . . . . . . .
Appendices
A Compiling and Loading Code
A.l Procedures with S-PLUS. . . . . .
A.2 Procedures with R . . . . . . . . . . . .
A.3 Common concerns . . . . . . . . .
A.4 Writing Dynamic Link Libraries for Windows
B The Interactive Environment
B.l History and audit trails . . . . . . . . . .
B.2 Options . . . . . . . . . . . . . . . . .
B.3 Session startup and finishing functions .
C BATCH Operation
C.l S-PLUS...
C.2 R . . . .
References
Index
IX
. . . . . 223
. . . . . . . 225
. . .. . 234
. . . 234
235
. . 235
. . .. . 239
. . .. . 240
. . . . . 241
247
. . . . . 247
. . .. . 249
. . 250
253
. 253
.254
255
257