ID EN
Miscellaneous

dput

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Menulis representasi teks ASCII dari objek R ke file atau koneksi, atau menggunakannya untuk membuat ulang objek tersebut.

Syntax

R
dput(x, file = "",
     control = c("keepNA", "keepInteger", "niceNames", "showAttributes"))<p></p><p>dget(file, keep.source = FALSE)</p>

Arguments

Parameter Deskripsi
x an object.
file either a character string naming a file or a connection. "" indicates output to the console.
control character vector indicating deparsing options. See .deparseOpts for their description.
keep.source logical: should the source formatting be retained when parsing functions, if possible?

Return Value

Untuk dput, argumen pertama tidak terlihat. Misalnya, objek dibuat.

Details

dput membuka file dan mendeparasi objek x ke dalam file itu. Nama objek tidak ditulis (tidak seperti dump). Jika x adalah suatu fungsi, lingkungan terkait akan dihapus. Oleh karena itu, informasi pelingkupan bisa hilang. Mendeparsing suatu objek itu sulit, dan tidak selalu memungkinkan. Dengan kontrol default, dput() mencoba melakukan deparse dengan cara yang mudah dibaca, namun untuk objek yang lebih kompleks atau tidak biasa (lihat dump), kemungkinan besar tidak akan diurai sama persis dengan aslinya. Gunakan control = "all" untuk deparsing terlengkap; gunakan control = NULL untuk deparsing paling sederhana, bahkan tidak menyertakan atribut. dput akan memperingatkan jika lebih sedikit karakter yang ditulis ke file dari yang diharapkan, yang mungkin menunjukkan sistem file penuh atau rusak. Untuk menampilkan sumber yang disimpan daripada menghapus representasi internal, sertakan "useSource" di co

Contoh

Example
R
# NOT RUN {
fil <- tempfile()
## Write an ASCII version of the 'base' function mean() to our temp file, ..
dput(base::mean, fil)
## ... read it back into 'bar' and confirm it is the same
bar <- dget(fil)
stopifnot(all.equal(bar, base::mean))

## Create a function with comments
baz <- function(x) {
  # Subtract from one
  1-x
}
## and display it
dput(baz)
## and now display the saved source
dput(baz, control = "useSource")

## Numeric values:
xx <- pi^(1:3)
dput(xx)
dput(xx, control = "digits17")
dput(xx, control = "hexNumeric")
dput(xx, fil); dget(fil) - xx # slight rounding on all platforms
dput(xx, fil, control = "digits17")
dget(fil) - xx # slight rounding on some platforms
dput(xx, fil, control = "hexNumeric"); dget(fil) - xx
unlink(fil)

xn <- setNames(xx, paste0("pi^",1:3))
dput(xn) # nicer, now "niceNames" being part of default 'control'
dput(xn, control = "S_compat") # no names
## explicitly asking for output as in R < 3.5.0:
dput(xn, control = c("keepNA", "keepInteger", "showAttributes"))
# }

See Also

deparse dump write.