-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sec-IntroR.Rnw
108 lines (93 loc) · 2.19 KB
/
Sec-IntroR.Rnw
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
\section{Hello woRld}
<<knitr, echo=FALSE>>=
opts_chunk$set(tidy.opts =
list(width.cutoff = 50,
tidy = FALSE),
fig.align = 'center',
stop_on_error = 1L,
comment = NA,
prompt = TRUE)
options(width = 60)
@
\begin{frame}[fragile]
\begin{block}{Hello woRld}
<<intro0>>=
5
2 + 2
sin(pi/2)
@
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{}
<<intro>>=
x <- 1 ## a variable
x
x = 2 ## overwrite the content of x
x
y <- length(x) ## calling a function
y
y + 2
@
\end{block}
\end{frame}
\begin{frame}[fragile]
<<env>>=
## just a comment
ls()
rm(y)
ls()
rm(list = ls())
ls()
@
\end{frame}
\begin{frame}[fragile]
\begin{block}{The working directory}
<<wd>>=
getwd()
setwd("/home/lgatto/tmp")
getwd()
@
\end{block}
(or use the GUI in RStudio)
\end{frame}
\begin{frame}[fragile]
\begin{block}{Functions: \Rfunction{fname(argument)}}
<<funs>>=
floor(2.3)
sum(3, 4, 10)
max(3, 10, 1, -0.2)
mean(3, 4, 5, 6) ## !
@
\end{block}
\end{frame}
\begin{frame}
\begin{block}{Getting help}
\begin{itemize}
\item Just ask!
\item \Rfunction{help.start()} and the HTML help button in the Windows GUI.
\item \Rfunction{help} and \Rfunction{?}: \Rfunction{help("sin")} or \Rfunction{?sin}.
\item \Rfunction{??}, \Rfunction{help.search}, \Rfunction{apropos}.
\item Online manuals and mailing lists.
\item Vignettes
\bigskip
\item Local R user groups
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{\exercise}
In the interactive \R console, calculate the following expressions,
where \Robject{x} and \Robject{y} have values \Robject{-0.25} and \Robject{2} respecively.
Then store the result in a new variable and print its content.
<<hello, eval = FALSE>>=
x + cos(pi/y)
@
\end{block}
Same, as above, but writing the code in an \R source code file using the editor.
Then, clean your working environment (delete all your variables) and execute the content
of that file.
\bigskip
New functions: \Rfunction{print} to explicitely print to the console and
\Rfunction{source} to execute the content of a file.
\end{frame}