-
Notifications
You must be signed in to change notification settings - Fork 285
/
Copy pathmelt_delim.Rd
185 lines (161 loc) · 6.37 KB
/
melt_delim.Rd
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/melt_delim.R
\name{melt_delim}
\alias{melt_delim}
\alias{melt_csv}
\alias{melt_csv2}
\alias{melt_tsv}
\title{Return melted data for each token in a delimited file (including csv & tsv)}
\usage{
melt_delim(
file,
delim,
quote = "\\"",
escape_backslash = FALSE,
escape_double = TRUE,
locale = default_locale(),
na = c("", "NA"),
quoted_na = TRUE,
comment = "",
trim_ws = FALSE,
skip = 0,
n_max = Inf,
progress = show_progress(),
skip_empty_rows = FALSE
)
melt_csv(
file,
locale = default_locale(),
na = c("", "NA"),
quoted_na = TRUE,
quote = "\\"",
comment = "",
trim_ws = TRUE,
skip = 0,
n_max = Inf,
progress = show_progress(),
skip_empty_rows = FALSE
)
melt_csv2(
file,
locale = default_locale(),
na = c("", "NA"),
quoted_na = TRUE,
quote = "\\"",
comment = "",
trim_ws = TRUE,
skip = 0,
n_max = Inf,
progress = show_progress(),
skip_empty_rows = FALSE
)
melt_tsv(
file,
locale = default_locale(),
na = c("", "NA"),
quoted_na = TRUE,
quote = "\\"",
comment = "",
trim_ws = TRUE,
skip = 0,
n_max = Inf,
progress = show_progress(),
skip_empty_rows = FALSE
)
}
\arguments{
\item{file}{Either a path to a file, a connection, or literal data
(either a single string or a raw vector).
Files ending in \code{.gz}, \code{.bz2}, \code{.xz}, or \code{.zip} will
be automatically uncompressed. Files starting with \verb{http://},
\verb{https://}, \verb{ftp://}, or \verb{ftps://} will be automatically
downloaded. Remote gz files can also be automatically downloaded and
decompressed.
Literal data is most useful for examples and tests. To be recognised as
literal data, the input must be either wrapped with \code{I()}, be a string
containing at least one new line, or be a vector containing at least one
string with a new line.
Using a value of \code{\link[=clipboard]{clipboard()}} will read from the system clipboard.}
\item{delim}{Single character used to separate fields within a record.}
\item{quote}{Single character used to quote strings.}
\item{escape_backslash}{Does the file use backslashes to escape special
characters? This is more general than \code{escape_double} as backslashes
can be used to escape the delimiter character, the quote character, or
to add special characters like \verb{\\\\n}.}
\item{escape_double}{Does the file escape quotes by doubling them?
i.e. If this option is \code{TRUE}, the value \verb{""""} represents
a single quote, \verb{\\"}.}
\item{locale}{The locale controls defaults that vary from place to place.
The default locale is US-centric (like R), but you can use
\code{\link[=locale]{locale()}} to create your own locale that controls things like
the default time zone, encoding, decimal mark, big mark, and day/month
names.}
\item{na}{Character vector of strings to interpret as missing values. Set this
option to \code{character()} to indicate no missing values.}
\item{quoted_na}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Should missing values
inside quotes be treated as missing values (the default) or strings. This
parameter is soft deprecated as of readr 2.0.0.}
\item{comment}{A string used to identify comments. Any text after the
comment characters will be silently ignored.}
\item{trim_ws}{Should leading and trailing whitespace (ASCII spaces and tabs) be trimmed from
each field before parsing it?}
\item{skip}{Number of lines to skip before reading data. If \code{comment} is
supplied any commented lines are ignored \emph{after} skipping.}
\item{n_max}{Maximum number of lines to read.}
\item{progress}{Display a progress bar? By default it will only display
in an interactive session and not while knitting a document. The automatic
progress bar can be disabled by setting option \code{readr.show_progress} to
\code{FALSE}.}
\item{skip_empty_rows}{Should blank rows be ignored altogether? i.e. If this
option is \code{TRUE} then blank rows will not be represented at all. If it is
\code{FALSE} then they will be represented by \code{NA} values in all the columns.}
}
\value{
A \code{\link[=tibble]{tibble()}} of four columns:
\itemize{
\item \code{row}, the row that the token comes from in the original file
\item \code{col}, the column that the token comes from in the original file
\item \code{data_type}, the data type of the token, e.g. \code{"integer"}, \code{"character"},
\code{"date"}, guessed in a similar way to the \code{guess_parser()} function.
\item \code{value}, the token itself as a character string, unchanged from its
representation in the original file.
}
If there are parsing problems, a warning tells you
how many, and you can retrieve the details with \code{\link[=problems]{problems()}}.
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}}
This function has been superseded in readr and moved to \href{https://r-lib.github.io/meltr/}{the meltr package}.
}
\details{
For certain non-rectangular data formats, it can be useful to parse the data
into a melted format where each row represents a single token.
\code{melt_csv()} and \code{melt_tsv()} are special cases of the general
\code{melt_delim()}. They're useful for reading the most common types of
flat file data, comma separated values and tab separated values,
respectively. \code{melt_csv2()} uses \verb{;} for the field separator and \verb{,} for the
decimal point. This is common in some European countries.
}
\examples{
# Input sources -------------------------------------------------------------
# Read from a path
melt_csv(readr_example("mtcars.csv"))
melt_csv(readr_example("mtcars.csv.zip"))
melt_csv(readr_example("mtcars.csv.bz2"))
\dontrun{
melt_csv("https://github.com/tidyverse/readr/raw/main/inst/extdata/mtcars.csv")
}
# Or directly from a string (must contain a newline)
melt_csv("x,y\n1,2\n3,4")
# To import empty cells as 'empty' rather than `NA`
melt_csv("x,y\n,NA,\"\",''", na = "NA")
# File types ----------------------------------------------------------------
melt_csv("a,b\n1.0,2.0")
melt_csv2("a;b\n1,0;2,0")
melt_tsv("a\tb\n1.0\t2.0")
melt_delim("a|b\n1.0|2.0", delim = "|")
}
\seealso{
\code{\link[=read_delim]{read_delim()}} for the conventional way to read rectangular data
from delimited files.
}