Membaca beberapa atau semua baris teks dari koneksi.
readLines(con = stdin(), n = -1L, ok = TRUE, warn = TRUE,
encoding = "unknown", skipNul = FALSE)
| Parameter | Deskripsi |
|---|---|
con |
a connection object or a character string. |
n |
integer. The (maximal) number of lines to read. Negative values indicate that one should read up to the end of input on the connection. |
ok |
logical. Is it OK to reach the end of the connection before n > 0 lines are read? If not, an error will be generated. |
warn |
logical. Warn if a text file is missing a final EOL or if there are embedded nuls in the file. |
encoding |
encoding to be assumed for input strings. It is used to mark character strings as known to be in Latin-1 or UTF-8: it is not used to re-encode the input. To do the latter, specify the encoding as part of the connection con or via options(encoding=): see the examples. See also ‘Details’. |
skipNul |
logical: should nuls be skipped? |
# NOT RUN {
fil <- tempfile(fileext = ".data")
cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = fil,
sep = "\n")
readLines(fil, n = -1)
unlink(fil) # tidy up
## difference in blocking
fil <- tempfile("test")
cat("123\nabc", file = fil)
readLines(fil) # line with a warning
con <- file(fil, "r", blocking = FALSE)
readLines(con) # empty
cat(" def\n", file = fil, append = TRUE)
readLines(con) # gets both
close(con)
unlink(fil) # tidy up
# }
# NOT RUN {
# read a 'Windows Unicode' file
A <- readLines(con <- file("Unicode.txt", encoding = "UCS-2LE"))
close(con)
unique(Encoding(A)) # will most likely be UTF-8
# }