ID EN
I/O & Files

files

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Fungsi-fungsi ini menyediakan antarmuka tingkat rendah ke sistem file komputer.

Syntax

R
file.create(…, showWarnings = TRUE)
file.exists(…)
file.remove(…)
file.rename(from, to)
file.append(file1, file2)
file.copy(from, to, overwrite = recursive, recursive = FALSE,
          copy.mode = TRUE, copy.date = FALSE)
file.symlink(from, to)
file.link(from, to)
Sys.junction(from, to)

Arguments

Parameter Deskripsi
…, file1, file2 character vectors, containing file names or paths.
from, to character vectors, containing file names or paths. For file.copy and file.symlink and Sys.junction to can alternatively be the path to a single existing directory.
overwrite logical; should existing destination files be overwritten?
showWarnings logical; should the warnings on failure be shown?
recursive logical. If to is a directory, should directories in from be copied (and their contents)? (Like cp -R on POSIX OSes.)
copy.mode logical: should file permission bits be copied where possible?
copy.date logical: should file dates be preserved where possible? See Sys.setFileTime.

Return Value

Fungsi-fungsi ini mengembalikan vektor logis yang menunjukkan operasi mana yang berhasil untuk setiap file yang dicoba. Menggunakan nilai yang hilang untuk nama file atau jalur akan selalu dianggap sebagai kegagalan. Jika showWarnings = TRUE, file.create akan memberikan peringatan kegagalan yang tidak terduga.

Details

Argumen … digabungkan untuk membentuk satu string karakter: Anda dapat menentukan file secara terpisah atau sebagai satu vektor. Semua fungsi ini memperluas nama jalur: lihat path.expand. file.create membuat file dengan nama tertentu jika belum ada dan memotongnya jika sudah ada. Mereka dibuat dengan izin baca/tulis maksimal yang diizinkan oleh pengaturan 'umask' (jika relevan). Secara default, peringatan diberikan (dengan alasannya) jika operasi gagal. file.exists mengembalikan vektor logis yang menunjukkan apakah file yang diberi nama berdasarkan argumennya ada. (Di sini 'ada' dalam arti panggilan stat sistem: file akan dilaporkan ada hanya jika Anda memiliki izin yang diperlukan oleh stat. Keberadaan juga dapat diperiksa dengan file.access, yang mungkin menggunakan izin berbeda sehingga memperoleh a

Contoh

Example
R
# NOT RUN {
cat("file A\n", file = "A")
cat("file B\n", file = "B")
file.append("A", "B")
file.create("A") # (trashing previous)
file.append("A", rep("B", 10))
if(interactive()) file.show("A") # -> the 10 lines from 'B'
file.copy("A", "C")
dir.create("tmp")
file.copy(c("A", "B"), "tmp")
list.files("tmp") # -> "A" and "B"
setwd("tmp")
file.remove("A") # the tmp/A file
file.symlink(file.path("..", c("A", "B")), ".")
                     # |--> (TRUE,FALSE) : ok for A but not B as it exists already
setwd("..")
unlink("tmp", recursive = TRUE)
file.remove("A", "B", "C")
# }

See Also

file.info file.access file.path file.show list.files unlink basename path.expand. dir.create. Sys.glob to expand wildcards in file specifications. file_test Sys.readlink (for ‘symlink’s). https://en.wikipedia.org/wiki/Hard_link and https://en.wikipedia.org/wiki/Symbolic_link for the concepts of links and their limitations.