Learn R Programming

reader (version 1.0.6)

cat.path: Simple and robust way to create full-path file names.

Description

Create a path with a file name, plus optional directory, prefix, suffix, and file extension. dir/ext are robust, so that if they already exist, the path produced will still make sense. Prefix is applied after the directory, and suffix before the file extension.

Usage

cat.path(dir = "", fn, pref = "", suf = "", ext = "", must.exist = FALSE)

Arguments

dir
directory for the full path, if 'fn' already has a dir, then dir will be overridden. Auto add file separator if not present
fn
compulsory vector of file names/paths
pref
prefix to add in front of the file name
suf
suffix to add after the file name, before the extension
ext
file extension, will override an existing extension
must.exist
the specified file must already exist, else error

Value

returns vector of file names with the full paths

Examples

Run this code
mydir <- "/Documents"
cat.path(mydir,"temp.doc")
# dir not added if one already present
cat.path(mydir,"/Downloads/me/temp.doc")
# using prefix and suffix
cat.path(mydir,"temp.doc","NEW",suf=5)
# changing the extension from .docx to .doc
cat.path(mydir,"temp.docx",ext="doc")

Run the code above in your browser using DataLab