Learn R Programming

this.path (version 1.2.0)

here: Construct Path to File, Beginning with this.dir()

Description

Construct the path to a file from components/paths in a platform-DEPENDENT way, starting with this.dir().

Usage

here(..., .. = 0)
ici(..., .. = 0)

Value

A character vector of the arguments concatenated term-by-term, beginning with the executing script's directory.

Arguments

...

further arguments passed to path.join().

..

the number of directories to go back.

Details

The path to a file begins with a base. The base is .. number of directories back from the executing script's directory (this.dir()). The argument is named .. because ".." refers to the parent directory in Windows, Unix, and URL paths alike.

Examples

Run this code
FILE <- tempfile(fileext = ".R")
this.path:::write.code({


    this.path::here()
    this.path::here(.. = 1)
    this.path::here(.. = 2)


    # use 'here' to read input from a file located nearby
    this.path::here(.. = 1, "input", "file1.csv")


    # or maybe to run another script
    this.path::here("script2.R")


}, FILE)


source(FILE, echo = TRUE, verbose = FALSE)
unlink(FILE)

Run the code above in your browser using DataLab