Skip to contents

This function moves the working directory up a specified number of levels in the directory hierarchy.

Usage

guide_to_parent(current_dir = getwd(), levels_up = 1)

Arguments

current_dir

A character string specifying the current directory name or path. Defaults to `getwd()`.

levels_up

An integer specifying how many levels up to move in the directory tree. Defaults to 1.

Value

The new working directory (invisibly) after moving up the directory tree.

Details

The function allows for traversing up the directory tree by the specified number of levels. It can handle both absolute and relative directory paths and throws an error if the current directory is invalid. If the directory provided in `current_dir` is invalid or unreachable, the function throws an error. If the user reaches the root directory,a warning is issued.

Examples

if (FALSE) { # \dontrun{
# Move up one level in the directory tree
guides::guide_to_parent()

# Move up two levels in the directory tree
guides::guide_to_parent(levels_up = 2)
} # }