Skip to contents

This function retrieves the directory name at a specified level(s) above the given file path. It wraps fs::path_dir() to navigate up directory levels and basename() to extract the final directory name. Particularly useful for retrieving repo name so it can be converted to url and or html link by ngr_str_link_repo().

Usage

ngr_str_dir_from_path(path, levels = 1)

Arguments

path

character A single string. The file path.

levels

integer A single integer. The number of levels up to traverse from the file path to extract the directory name. Default is 1.

Value

character A single string representing the directory name at the specified level.

See also

Other string: ngr_str_link_url()

Examples

ngr_str_dir_from_path("~/Projects/repo/ngr/data-raw/extdata.R", levels = 2)
#> [1] "ngr"
# Returns "ngr"