getFiles: Retrieve theme files

Description Usage Arguments Details Value Author(s) Examples

View source: R/utils.R

Description

A wrapper for file.copy that retieves files from the dn = "theme" directory of a package. It ties in the file.backup function from kutils so that if a file is overwritten, then a backup copy is created, using the last modification time of the file in the backup file name.

Usage

1
2
3
4
5
6
7
8
getFiles(
  fn,
  pkg = "stationery",
  overwrite = FALSE,
  backup = overwrite,
  pkgdir = "theme",
  outputdir = "theme"
)

Arguments

fn

A file name vector. In stationery, this is typically retrieving logo images or theme files.

pkg

Package name, default "stationery"

overwrite

Default FALSE, function returns TRUE, meaning "my work was done before." If TRUE, old file will be replaced.

backup

Default is TRUE, if a file is to be overwritten, then a backup will be created with kutils::file.backup.

pkgdir

package directory name where files are found. Default is "theme" because that is used in stationery and related CRMDA packages. It is the name of a directory in the package's inst folder, the same place where R system.file looks for files and directories.

outputdir

Default is same as pkgdir. A directory where file file will be copied within the current working directory.

Details

This was originally created because we wanted to protect user logo and address files from accidental erasure. Now it has a little more versatility because overwrite=TRUE and backup=TRUE add a little bit of valuable functionality. When a file is overwritten, it should never be lost if backup=TRUE.

Value

TRUE if succeeded, either a file existed before (and overwrite=FALSE) or a file was copied.

Author(s)

Paul Johnson<pauljohn@ku.edu>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## To demonstrate, we use a temporary directory.  Usage of setwd is discouraged
## in examples, so this is a little bit more indirect than a real usage would be:
tdir <- tempdir()
list.files(file.path(tdir, "theme"))
getFiles("logo.pdf", pkg = "stationery", overwrite = TRUE, outputdir = file.path(tdir, "theme"))
list.files(file.path(tdir, "theme"))
getFiles("logo.pdf", pkg = "stationery", overwrite = TRUE, outputdir = file.path(tdir, "theme"),
         backup = TRUE)
list.files(file.path(tdir, "theme"))
unlink(file.path(tdir, "theme"), recursive = TRUE)

stationery documentation built on April 28, 2020, 5:13 p.m.