R - File System (File, Directory)

Card Puncher Data Processing


File (System, Transfer, Storage) in R

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


Special Directory

R Home

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

User Home

[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


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


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.

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


  • 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



  • File Time: Sys.setFileTime()


See R Admin - OS (Platform, Sys, )

[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