R - File System (File, Directory)

Card Puncher Data Processing

About

File (System, Transfer, Storage) in R

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

Management

Special Directory

R Home

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

User Home

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

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")

Temporary

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

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.

List files in a directory

dir()

Time

  • File Time: Sys.setFileTime()

Separator

See R Admin - OS (Platform, Sys, )

.Platform$file.sep
[1] "/"





Discover More
Card Puncher Data Processing
R - Connection (Stream)

Data are read in using connection interfaces: file, gzfile, (a file compressed with gzip) bzfile, (a file compressed with bzip2) url (an HTTP location) where: stdin, stdout and stderr are...
Card Puncher Data Processing
R - Read.Table

The Read.Table function reads a file in table format and creates a data frame from it, with cases corresponding to lines and variables to fields in the file. where: file can be a file, an Url or...
Card Puncher Data Processing
R - Script (.R file)

R script are file with an R extension. You can load a script with the source function see commandArgs()
Undraw File Manager Re Ms29
What is the working or current directory ?

The current or working directory is the directory where all relative directories are calculated



Share this page:
Follow us:
Task Runner