MyNixOS website logo
Description

Easy Management of File Names.

Create descriptive file names with ease. New file names are automatically (but optionally) time stamped and placed in date stamped directories. Streamline your analysis pipeline with input and output file names that have informative tags and proper file extensions.

README

filenamer is an R package for managing file names with time stamps, tags, and subdirectories. It facilitates quick derivation of new file names and supports conversions to and from character vectors.

Dependencies

  • R (>= 3.0)
  • roxygen2 (>= 4.0, for building only)

Build

Clone the repository, build the documentation with roxygen2, then install.

$ git clone https://bitbucket.org/djhshih/filenamer.git
$ cd filename
$ R

R> library(roxygen2)
R> roxygenize()
R> quit()

$ R CMD INSTALL .

Usage

library(filenamer)

We can create a filenamer object by conversion from a character vector.

f <- as.filename("cars.txt")

Alternatively, we can use the filename constructor, which by default apply a time stamp (when the file name is created) and places the target file in a date-stamped directory.

f <- filename("cars", ext="txt")
as.character(f)
## [1] "2014-12-09/cars_20141209T184403.txt"

# tag() tags a file name and returns the resulting character vector;
# without any extra argument, tag() just type casts
tag(f)
## [1] "2014-12-09/cars_20141209T184403.txt"

We can also do only date stamping, or turn off the stamping completely.

# Set option to enable only date stamping
options(filename.timestamp=1)

# Disable automatic date-stamped subdirectory placement
options(filename.path.timestamp=0) 

f <- filename("cars", ext="txt")
tag(f)
## [1] "cars_2014-12-09.txt"

# Set option to disable stamping
options(filename.timestamp=0)

f <- filename("cars", ext="txt")
tag(f)
## [1] "cars.txt"

We can manage filename (or character) using insert.

# Insert a tag to derive a new file name for the normalized data
g <- insert(f, tag="norm")
tag(g)
## [1] "cars_norm.txt"

# Replace the extension
# (if we start with a character vector, we end with a character vector)
g <- set_ext("cars.txt", "csv")
g 
## [1] "cars.csv"

We can also use the tag function for insert + as.character.

data(cars)
pdf(tag(f, ext="pdf", replace=TRUE))
plot(dist ~ speed, cars)
dev.off()

Together with the io package, we can name and create files painlessly with time stamping and directory organization. The directory structure is automatically created by io::qwrite.

# Set options back to default values
options(filename.timestamp=2)
options(filename.path.timestamp=1) 

library(io)
f <- filename("cars", path="out", ext="txt")
qwrite(cars, f)
qdraw(plot(dist ~ speed, cars), set_fext(f, "pdf"))

# Sometimes when the plot has many graphical elements,
# you may wish to output the plot in a bitmap format;
# you do so by simply changing the file extension
qdraw(plot(dist ~ speed, cars), set_fext(f, "png"))

list.files("out/2014-12-09")
## [1] "cars_20141209T191048.pdf" "cars_20141209T191048.txt"

The time stamps on the file names prevent them from being clobbered on repeat runs (that are more than a second apart). The files are automatically organized into subdirectories. Accordingly, you can keep all versions of your results, and you have ready access to the latest version in the base directory:

# Symbolic links are automatically created with simpler names
list.files("out", pattern="cars")
## [1] "cars.pdf" "cars.txt"

See ?filename and ?io.

Metadata

Version

0.2.4

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows