-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathconnections.tex
98 lines (78 loc) · 2.06 KB
/
connections.tex
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
\documentclass[aspectratio=169]{beamer}
\mode<presentation>
{
\usetheme{Warsaw}
% or ...
\setbeamercovered{transparent}
% or whatever (possibly just delete it)
}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}
%\usepackage{times}
%\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.
\usepackage{amsmath,amsfonts,amssymb}
\input{macros}
\title[The R Language]{Introduction to the R Language}
\subtitle{Connections}
\date{Computing for Data Analysis}
\setbeamertemplate{footline}[page number]
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}{Interfaces to the Outside World}
Data are read in using \textit{connection} interfaces. Connections
can be made to files (most common) or to other more exotic things.
\begin{itemize}
\item
\code{file}, opens a connection to a file
\item
\code{gzfile}, opens a connection to a file compressed with gzip
\item
\code{bzfile}, opens a connection to a file compressed with bzip2
\item
\code{url}, opens a connection to a webpage
\end{itemize}
\end{frame}
\begin{frame}[fragile]{File Connections}
\begin{verbatim}
> str(file)
function (description = "", open = "", blocking = TRUE,
encoding = getOption("encoding"))
\end{verbatim}
\begin{itemize}
\item
\code{description} is the name of the file
\item
\code{open} is a code indicating
\begin{itemize}
\item
``r'' read only
\item
``w'' writing (and initializing a new file)
\item
``a'' appending
\item
``rb'', ``wb'', ``ab'' reading, writing, or appending in binary mode
(Windows)
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Connections}
In general, connections are powerful tools that let you navigate files
or other external objects. In practice, we often don't need to deal
with the connection interface directly.
\begin{verbatim}
con <- file("foo.txt", "r")
data <- read.csv(con)
close(con)
\end{verbatim}
is the same as
\begin{verbatim}
data <- read.csv("foo.txt")
\end{verbatim}
\end{frame}
\end{document}