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

ch02()

ch2()

See also

toc

Other Chapters: ch01, ch03, ch04, ch05, ch06, ch07, ch08, ch09, ch10, ch11, ch12, ch13, ch14, ch15, ch16, ch17, ch18, ch19, ch20

Examples

# Chapter 2 - Exploring R # Working with a Code Editor ## Exploring RGui ### Seeing the naked R console ### Issuing a simple command 24+7+11
#> [1] 42
### Closing the console
# NOT RUN { quit() # }
## Dressing up with RStudio # Starting Your First R Session ## Saying hello to the world print("Hello world!")
#> [1] "Hello world!"
## Doing simple math 1+2+3+4+5
#> [1] 15
## Using vectors c(1,2,3,4,5)
#> [1] 1 2 3 4 5
1:5
#> [1] 1 2 3 4 5
sum(1:5)
#> [1] 15
## Storing and calculating values x <- 1:5 x
#> [1] 1 2 3 4 5
y <- 10 x + y
#> [1] 11 12 13 14 15
x
#> [1] 1 2 3 4 5
y
#> [1] 10
z <- x + y z
#> [1] 11 12 13 14 15
h <- "Hello" h
#> [1] "Hello"
hw <- c("Hello", "world!") hw
#> [1] "Hello" "world!"
paste("Hello", "world!")
#> [1] "Hello world!"
## Talking back to the user h <- "Hello" if(interactive()){ yourname <- readline("What is your name?") } else { yourname <- "Joris" } paste(h, yourname)
#> [1] "Hello Joris"
# Sourcing a Script h <- "Hello" yourname <- readline("What is your name?")
#> What is your name?
print(paste(h, yourname))
#> [1] "Hello "
### Finding help on functions ?paste help(paste) # Navigating the Workspace ls()
#> [1] "h" "hw" "x" "y" "yourname" "z"
## Manipulating the content of the workspace rm(z) ls()
#> [1] "h" "hw" "x" "y" "yourname"
##Saving your work getwd()
#> [1] "C:/Users/apdev/Documents/github/R-packages/maintainer/rfordummies/docs/reference"
filename <- file.path(tempdir(), "yourname.rda")
# NOT RUN { save(yourname, file=filename) # }
list.files(tempdir(), pattern = ".rda")
#> character(0)
## Retrieving your work rm(yourname)
# NOT RUN { load("yourname.rda") # }