ID EN
I/O & Files

readRDS

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Berfungsi untuk menulis satu objek R ke sebuah file, dan memulihkannya.

Syntax

R
saveRDS(object, file = "", ascii = FALSE, version = NULL,
        compress = TRUE, refhook = NULL)<p></p><p>readRDS(file, refhook = NULL)</p>

Arguments

Parameter Deskripsi
object R object to serialize.
file a connection or the name of the file where the R object is saved to or read from.
ascii a logical. If TRUE or NA, an ASCII representation is written; otherwise (default), a binary one is used. See the comments in the help for save.
version the workspace format version to use. NULL specifies the current default version (3). The only other supported value is 2, the default from R 1.4.0 to R 3.5.0.
compress a logical specifying whether saving to a named file is to use "gzip" compression, or one of "gzip", "bzip2" or "xz" to indicate the type of compression to be used. Ignored if file is a connection.
refhook a hook function for handling reference objects.

Return Value

Untuk readRDS, objek R. Untuk saveRDS, NULL tidak terlihat.

Details

Fungsi-fungsi ini menyediakan sarana untuk menyimpan objek R tunggal ke koneksi (biasanya file) dan memulihkan objek, sangat mungkin dengan nama yang berbeda. Ini berbeda dari simpan dan muat, yang menyimpan dan memulihkan satu atau lebih objek bernama ke dalam suatu lingkungan. Mereka banyak digunakan oleh R sendiri, misalnya untuk menyimpan metadata suatu paket dan untuk menyimpan database help.search: ekstensi file ".rds" paling sering digunakan. Fungsi serialisasi dan unserialize menyediakan antarmuka tingkat yang sedikit lebih rendah untuk serialisasi: objek yang diserialkan ke koneksi dengan serialisasi dapat dibaca kembali oleh readRDS dan sebaliknya. Semua antarmuka ini menggunakan format serialisasi yang sama, yang telah digunakan sejak R 1.4.0 (tetapi diperluas dari waktu ke waktu seiring dengan penambahan tipe objek baru ke R). Namun, simpan saja

Contoh

Example
R
# NOT RUN {
fil <- tempfile("women", fileext = ".rds")
## save a single object to file
saveRDS(women, fil)
## restore it under a different name
women2 <- readRDS(fil)
identical(women, women2)
## or examine the object via a connection, which will be opened as needed.
con <- gzfile(fil)
readRDS(con)
close(con)

## Less convenient ways to restore the object
## which demonstrate compatibility with unserialize()
con <- gzfile(fil, "rb")
identical(unserialize(con), women)
close(con)
con <- gzfile(fil, "rb")
wm <- readBin(con, "raw", n = 1e4) # size is a guess
close(con)
identical(unserialize(wm), women)

## Format compatibility with serialize():
fil2 <- tempfile("women")
con <- file(fil2, "w")
serialize(women, con) # ASCII, uncompressed
close(con)
identical(women, readRDS(fil2))
fil3 <- tempfile("women")
con <- bzfile(fil3, "w")
serialize(women, con) # binary, bzip2-compressed
close(con)
identical(women, readRDS(fil3))

unlink(c(fil, fil2, fil3))
# }

See Also

serialize save and load. The ‘R Internals’ manual for details of the format used.