Skip to content

Commit ed2885d

Browse files
authoredNov 12, 2018
Merge pull request rstudio-education#10 from cwickham/master
Minor fixes to S3 chapter
2 parents 451fe76 + 51d23be commit ed2885d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed
 

‎s3.rmd

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ R's S3 system is built around three components: attributes (especially the `clas
5656

5757
In [Attributes](#attributes), you learned that many R objects come with attributes, pieces of extra information that are given a name and appended to the object. Attributes do not affect the values of the object, but stick to the object as a type of metadata that R can use to handle the object. For example, a data frame stores its row and column names as attributes. Data frames also store their class, `"data.frame"`, as an attribute.
5858

59-
You can see an object's attributes with `attribute`. If you run `attribute` on the `DECK` data frame that you created in [Project 2: Playing Cards], you will see:
59+
You can see an object's attributes with `attribute`. If you run `attribute` on the `deck` data frame that you created in [Project 2: Playing Cards], you will see:
6060

6161
```r
62-
attributes(DECK)
62+
attributes(deck)
6363
## $names
6464
## [1] "face" "suit" "value"
6565
##
@@ -75,7 +75,7 @@ attributes(DECK)
7575
R comes with many helper functions that let you set and access the most common attributes used in R. You've already met the `names`, `dim`, and `class` functions, which each work with an eponymously named attribute. However, R also has `row.names`, `levels`, and many other attribute-based helper functions. You can use any of these functions to retrieve an attribute's value:
7676

7777
```r
78-
row.names(DECK)
78+
row.names(deck)
7979
## [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13"
8080
## [14] "14" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26"
8181
## [27] "27" "28" "29" "30" "31" "32" "33" "34" "35" "36" "37" "38" "39"
@@ -85,15 +85,15 @@ row.names(DECK)
8585
or to change an attribute's value:
8686

8787
```r
88-
row.names(DECK) <- 101:152
88+
row.names(deck) <- 101:152
8989
```
9090

9191
or to give an object a new attribute altogether:
9292

9393
```r
94-
levels(DECK) <- c("level 1", "level 2", "level 3")
94+
levels(deck) <- c("level 1", "level 2", "level 3")
9595

96-
attributes(DECK)
96+
attributes(deck)
9797
## $names
9898
## [1] "face" "suit" "value"
9999
##
@@ -226,11 +226,11 @@ slot_display <- function(prize){
226226
# collapse symbols into single string
227227
symbols <- paste(symbols, collapse = " ")
228228

229-
# combine symbol with prize as a regular expression
230-
# \n is regular expression for new line (i.e. return or enter)
229+
# combine symbol with prize as a character string
230+
# \n is special escape sequence for a new line (i.e. return or enter)
231231
string <- paste(symbols, prize, sep = "\n$")
232232

233-
# display regular expression in console without quotes
233+
# display character string in console without quotes
234234
cat(string)
235235
}
236236

0 commit comments

Comments
 (0)
Please sign in to comment.