# ch03: Print examples of chapter 3 of 'R for Dummies'. In rfordummies: Code Examples to Accompany the Book "R for Dummies"

## Description

To print a listing of all examples of a chapter, use `ch3()`. To run all the examples of `ch3()`, use `example(ch3)`.

## Usage

 ```1 2 3``` ```ch03() ch3() ```

`toc`
Other Chapters: `ch01`, `ch02`, `ch04`, `ch05`, `ch06`, `ch07`, `ch08`, `ch09`, `ch10`, `ch11`, `ch12`, `ch13`, `ch14`, `ch15`, `ch16`, `ch17`, `ch18`, `ch19`, `ch20`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92``` ```# Chapter 3 - The Fundamentals of R # Using the Full Power of Functions ## Vectorizing your functions baskets.of.Granny <- c(12,4,4,6,9,3) baskets.of.Granny sum(baskets.of.Granny) firstnames <- c("Joris", "Carolien", "Koen") lastname <- "Meys" paste(firstnames,lastname) authors <- c("Andrie","Joris") lastnames <- c("de Vries","Meys") paste(authors,lastnames) ## Putting the argument in a function # print() ### This line of code leads to deliberate error for illustration print(x = "Isn't this fun?") print(digits=4, x = 11/7) # Making history filename <- file.path(tempdir(), "Chapter3.Rhistory") ## Not run: savehistory(file = filename) ## End(Not run) list.files(tempdir(), pattern = ".Rhistory") ## Not run: loadhistory(file.path(tempdir(), "Chapter3.Rhistory")) ## End(Not run) # Keeping Your Code Readable ## Following naming conventions ## Choosing a clear name paste <- paste("This gets","confusing") paste paste("Don't","you","think?") ## Choosing a naming style ## Structuring your code baskets.of.Geraldine <- c(5,3,2,2,12,9) Intro <- "It is amazing! The All Star Grannies scored a total of" Outro <- "baskets in the last six games!" Total.baskets <- baskets.of.Granny + baskets.of.Geraldine Text <- paste(Intro, sum(Total.baskets), Outro) cat(Text) Text cat('If you doubt whether it works, + just try it out.') ## Adding comments # The All Star Grannies do it again! baskets.of.Granny <- c(12,4,4,6,9,3) # Granny rules sum(baskets.of.Granny) # total number of points # Getting from Base R to More ## Finding packages ## Installing packages ## Not run: install.packages("fortunes") ## End(Not run) library("fortunes") fortune("This is R") fortune(161) detach(package:fortunes) ```