Fungsi-fungsi ini menyediakan antarmuka tingkat rendah ke sistem file komputer.
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)
| 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. |
# 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")
# }