Format the path to an image file

format_path(file, dir, path.type = c("proj", "none", "raw"))

Arguments

file

the name of the image file.

dir

the directory where the image file is stored.

path.type

a character string indicating how the path to the image file should be formatted; use "proj" to have the path expressed relative to the RStudio project file; use "none" to format without any directory information (just the image file name); use "raw" to print the complete path to the file using dir as-is.

Value

A string with the formatted image file path.

Details

Note that the default value for path.type is "proj". This requires that an RStudio project file is able to be found using rprojroot::find_root() with the rprojroot::is_rstudio_project criterion.

Once mrggsave finds a root for a given working directory, it caches the value for the remainder of the R session. An error will be generated if an image is attempted to be saved using path.type="proj" but an RStudio project file was not able to be located.

Examples

if (FALSE) {
format_path("foo.txt", "my/path")
format_path("foo.txt", "my/path", path.type = "none")
format_path("foo.txt", "my/path", path.type = "raw")
}