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

Description Usage Arguments Value Author(s) Examples

View source: R/reader.R

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

1
2
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

Author(s)

Nicholas Cooper nick.cooper@cimr.cam.ac.uk

Examples

1
2
3
4
5
6
7
8
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")

Example output

Loading required package: NCmisc

Attaching package: 'reader'

The following objects are masked from 'package:NCmisc':

    cat.path, get.ext, rmv.ext

[1] "/Documents/temp.doc"
[1] "/Downloads/me/temp.doc"
[1] "/Documents/NEWtemp.doc5"
[1] "/Documents/temp.doc"

reader documentation built on May 2, 2019, 9:27 a.m.