ID EN
I/O & Files

textConnection

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Koneksi teks input dan output.

Syntax

R
textConnection(object, open = "r", local = FALSE,
               encoding = c("", "bytes", "UTF-8"))<p></p><p>textConnectionValue(con)</p>

Arguments

Parameter Deskripsi
object character. A description of the connection. For an input this is an R character vector object, and for an output connection the name for the R character vector to receive the output, or NULL (for none).
open character string. Either "r" (or equivalently "") for an input connection or "w" or "a" for an output connection.
local logical. Used only for output connections. If TRUE, output is assigned to a variable in the calling environment. Otherwise the global environment is used.
encoding character string, partially matched. Used only for input connections. How marked strings in object should be handled: converted to the current locale, used byte-by-byte or translated to UTF-8.
con An output text connection.

Return Value

Untuk textConnection, objek koneksi kelas "textConnection" yang mewarisi dari kelas "koneksi". Untuk textConnectionValue, vektor karakter.

Details

Koneksi teks input dibuka dan vektor karakter disalin pada saat objek koneksi dibuat, dan close menghancurkan salinannya. objek harus berupa nama vektor karakter: namun, ekspresi pendek akan diterima asalkan ukurannya kurang dari 60 byte. Koneksi teks keluaran dibuka dan membuat vektor karakter R dari nama yang diberikan di ruang kerja pengguna atau di lingkungan panggilan, bergantung pada nilai argumen lokal. Objek ini akan selalu menampung jalur keluaran yang telah selesai ke koneksi, dan isIncomplete akan menunjukkan jika ada jalur akhir yang belum lengkap. Menutup koneksi akan menghasilkan baris terakhir, lengkap atau tidak. (Sebuah baris selesai setelah diakhiri oleh akhir baris, diwakili oleh "\n" di R.) Karakter keluaran

Contoh

Example
R
# NOT RUN {
zz <- textConnection(LETTERS)
readLines(zz, 2)
scan(zz, "", 4)
pushBack(c("aa", "bb"), zz)
scan(zz, "", 4)
close(zz)

zz <- textConnection("foo", "w")
writeLines(c("testit1", "testit2"), zz)
cat("testit3 ", file = zz)
isIncomplete(zz)
cat("testit4\n", file = zz)
isIncomplete(zz)
close(zz)
foo

# }
# NOT RUN {
# capture R output: use part of example from help(lm)
zz <- textConnection("foo", "w")
ctl <- c(4.17, 5.58, 5.18, 6.11, 4.5, 4.61, 5.17, 4.53, 5.33, 5.14)
trt <- c(4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69)
group <- gl(2, 10, 20, labels = c("Ctl", "Trt"))
weight <- c(ctl, trt)
sink(zz)
anova(lm.D9 <- lm(weight ~ group))
cat("\nSummary of Residuals:\n\n")
summary(resid(lm.D9))
sink()
close(zz)
cat(foo, sep = "\n")
# }

See Also

connections showConnections pushBack capture.output.