Example: marketing

R Language Definition

R Language DefinitionVersion (2021-11-01)DRAFTR Core TeamThis manual is for R, version (2021-11-01).Copyrightc 2000 2021 R Core TeamPermission is granted to make and distribute verbatim copies of this manual providedthe copyright notice and this permission notice are preserved on all is granted to copy and distribute modified versions of this manual underthe conditions for verbatim copying, provided that the entire resulting derived workis distributed under the terms of a permission notice identical to this is granted to copy and distribute translations of this manual into an-other Language , under the above conditions for modified versions, except that thispermission notice may be stated in a translation approved by the R Core of Contents1 Basic types.. Vectors.. Lists.. Language objects.. Symbol objects.. Expression objects.. Function objects.

1 1 Introduction R is a system for statistical computation and graphics. It provides, among other things, a pro-gramming language, high level graphics, interfaces to other languages and debugging facilities.

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of R Language Definition

1 R Language DefinitionVersion (2021-11-01)DRAFTR Core TeamThis manual is for R, version (2021-11-01).Copyrightc 2000 2021 R Core TeamPermission is granted to make and distribute verbatim copies of this manual providedthe copyright notice and this permission notice are preserved on all is granted to copy and distribute modified versions of this manual underthe conditions for verbatim copying, provided that the entire resulting derived workis distributed under the terms of a permission notice identical to this is granted to copy and distribute translations of this manual into an-other Language , under the above conditions for modified versions, except that thispermission notice may be stated in a translation approved by the R Core of Contents1 Basic types.. Vectors.. Lists.. Language objects.. Symbol objects.. Expression objects.. Function objects.

2 NULL.. Builtin objects and special forms.. Promise objects.. Dot-dot-dot.. Environments.. Pairlist objects.. The Any type.. Attributes.. Names.. Dimensions.. Dimnames.. Classes.. Time series attributes.. Copying of attributes.. Special compound objects.. Factors.. Data frame objects..83 Evaluation of Simple evaluation.. Constants.. Symbol lookup.. Function calls.. Operators.. Control structures.. if.. Looping.. repeat.. while.. for.. switch.. Elementary arithmetic operations.. Recycling rules.. Propagation of names.. Dimensional attributes.. NA handling.. Indexing.. Indexing by vectors.. Indexing matrices and arrays.. Indexing other structures.. Subset assignment.. Scope of variables.. Global environment.. Lexical environment.

3 The call stack.. Search path..214 Writing functions.. Syntax and examples.. Arguments.. Functions as objects.. Evaluation.. Evaluation environment.. Argument matching.. Argument evaluation.. Scope..245 Object-oriented Definition .. Inheritance.. Method dispatching.. UseMethod.. NextMethod.. Group methods.. Writing methods..306 Computing on the Direct manipulation of Language objects.. Substitutions.. More on evaluation.. Evaluation of expression objects.. Manipulation of function calls.. Manipulation of functions..387 System and foreign Language Operating system access.. Foreign Language interfaces..Internal and .Primitive..418 Exception stop.. warning.. Error options..42iii9 browser.. debug/undebug.. trace/untrace.. traceback..4410 The parsing process.

4 Modes of parsing.. Internal representation.. Deparsing.. Comments.. Tokens.. Constants.. Identifiers.. Reserved words.. Special operators.. Separators.. Operator tokens.. Grouping.. Indexing tokens.. Expressions.. Function calls.. Infix and prefix operators.. Index constructions.. Compound expressions.. Flow control elements.. Function definitions.. Directives..51 Function and Variable A IntroductionR is a system for statistical computation and graphics. It provides, among other things, a pro-gramming Language , high level graphics, interfaces to other languages and debugging manual details and defines the R R Language is a dialect of S which was designed in the 1980s and has been in widespreaduse in the statistical community since. Its principal designer, John M. Chambers, was awardedthe 1998 ACM Software Systems Award for Language syntax has a superficial similarity with C, but the semantics are of the FPL(functional programming Language ) variety with stronger affinities with Lisp andAPL.

5 In par-ticular, it allows computing on the Language , which in turn makes it possible to write functionsthat take expressions as input, something that is often useful for statistical modeling and is possible to get quite far using R interactively, executing simple expressions from thecommand line. Some users may never need to go beyond that level, others will want to writetheir own functions either in an ad hoc fashion to systematize repetitive work or with theperspective of writing add-on packages for new purpose of this manual is to document the languageper se. That is, the objects that itworks on, and the details of the expression evaluation process, which are useful to know whenprogramming R functions. Major subsystems for specific tasks, such as graphics, are only brieflydescribed in this manual and will be documented much of the text will equally apply to S, there are also some substantial differences,and in order not to confuse the issue we shall concentrate on describing design of the Language contains a number of fine points and common pitfalls which maysurprise the user.

6 Most of these are due to consistency considerations at a deeper level, as weshall explain. There are also a number of useful shortcuts and idioms, which allow the userto express quite complicated operations succinctly. Many of these become natural once one isfamiliar with the underlying concepts. In some cases, there are multiple ways of performing atask, but some of the techniques will rely on the Language implementation, and others work ata higher level of abstraction. In such cases we shall indicate the preferred familiarity with R is assumed. This is not an introduction to R but rather a pro-grammers reference manual. Other manuals provide complementary information: in particularSection Preface inAn Introduction to Rprovides an introduction to R andSection Systemand foreign Language interfaces inWriting R Extensionsdetails how to extend R using ObjectsIn every computer Language variables provide a means of accessing the data stored in does not provide direct access to the computer s memory but rather provides a numberof specialized data structures we will refer to as objects.

7 These objects are referred to throughsymbols or variables. In R, however, the symbols are themselves objects and can be manipulatedin the same way as any other object. This is different from many other languages and has wideranging this chapter we provide preliminary descriptions of the various data structures providedin R. More detailed discussions of many of them will be found in the subsequent chapters. TheR specific functiontypeofreturns thetypeof an R object. Note that in the C code underlyingR, all objects are pointers to a structure with typedefSEXPREC; the different R data types arerepresented in C bySEXPTYPE, which determines how the information in the various parts ofthe structure is following table describes the possible values returned bytypeofand what they are."NULL"NULL"symbol"a variable name"pairlist"a pairlist object (mainly internal)"closure"a function"environment"an environment"promise"an object used to implement lazy evaluation" Language "an R Language construct"special"an internal function that does not evaluate its arguments"builtin"an internal function that evaluates its arguments"char"a scalar string object (internal only) **"logical"a vector containing logical values"integer"a vector containing integer values"double"a vector containing real values"complex"a vector containing complex values"character"a vector containing character values".

8 "the special variable length argument **"any"a special type that matches all types: there are no objectsof this type"expression"an expression object"list"a list"bytecode"byte code (internal only) **"externalptr"an external pointer object"weakref"a weak reference object"raw"a vector containing bytes"S4"an S4 object which is not a simple objectUsers cannot easily get hold of objects of types marked with a ** .Functionmodegives information about themodeof an object in the sense of Becker, Cham-bers & Wilks (1988), and is more compatible with other implementations of the S , the thestorage modeof its argument in the sense ofBecker et al. (1988). It is generally used when calling functions written in another Language ,such as C or FORTRAN, to ensure that R objects have the data type expected by the routinebeing called. (In the S Language , vectors with integer or real values are both of mode"numeric",so their storage modes need to be distinguished.)

9 > x <- 1:3> typeof(x)Chapter 2: Objects3[1] "integer"> mode(x)[1] "numeric"> (x)[1] "integer"R objects are often coerced to different types during computations. There are also manyfunctions available to perform explicit coercion. When programming in the R Language thetype of an object generally doesn t affect the computations, however, when dealing with foreignlanguages or the operating system it is often necessary to ensure that an object is of the Basic VectorsVectors can be thought of as contiguous cells containing data. Cells are accessed throughindexing operations such asx[5]. More details are given inSection [Indexing], page has six basic ( atomic ) vector types: logical, integer, real, complex, string (or character)and raw. The modes and storage modes for the different vector types are listed in the logical logicalinteger numeric integerdouble numeric doublecomplex complex complexcharacter character characterraw raw rawSingle numbers, such , and strings, such as"four point two"are still vectors, of length1; there are no more basic types.

10 Vectors with length zero are possible (and useful).String vectors have mode and storage mode"character". A single element of a charactervector is often referred to as acharacter ListsLists ( generic vectors ) are another kind of data storage. Lists have elements, each of whichcan contain any type of R object, the elements of a list do not have to be of the same elements are accessed through three different indexing operations. These are explained indetail inSection [Indexing], page are vectors, and the basic vector types are referred to asatomic vectorswhere it isnecessary to exclude Language objectsThere are three types of objects that constitute the R Language . They arecalls,expressions,andnames. Since R has objects of type"expression"we will try to avoid the use of the wordexpression in other contexts. In particular syntactically correct expressions will be referred objects have modes"call","expression", and"name", can be created directly from expressions using thequotemechanism and converted toand from lists by Components of the parse tree can beextracted using the standard indexing 2: Symbol objectsSymbols refer to R objects.


Related search queries