When called out of RStudio API returns the current path of the active file without the file name.

get.current.file.path()

Value

A character value defining the current path.

Examples

if(rstudioapi::isAvailable()) get.current.file.path()