R - File System (File, Directory)

1 - About

File (System, Transfer, Storage) in R

See also: system.file {base} to finds the full file names of files in packages etc.

3 - Management

3.1 - Special Directory

3.1.1 - R Home

R.home(component = "home")
[1] "C:\\Users\\gerard\\Documents"

3.1.2 - User Home

path.expand("~")
[1] "C:\\Users\\gerard\\Documents"

3.1.3 - Working Directory

  • To get the working directory, use the function getwd
  • To set the working directory, use the function setwd

Example:

> getwd()
[1] "C:/Users/gerard/Documents"
> setwd("C:/Users/gerard/Desktop")

3.1.4 - Temporary

tempDir <- tempdir()
tempFile <- paste0(tempDir , "/temp.txt")
temp_csv <- tempfile(fileext = ".csv")

3.2 - Create, open and close a file

File is a function to create, open and close a file.

file(
     description = "",
     open = "", 
     blocking = TRUE,
     encoding = getOption("encoding"), 
     raw = FALSE
     )

where:

  • description is the path to the file (If it does not contain an absolute path, the file name is relative to the current working directory)
  • open indicates the open mode.

3.3 - List files in a directory

dir()

3.4 - Time

  • File Time: Sys.setFileTime()
lang/r/fs.txt · Last modified: 2018/06/19 12:21 by gerardnico