knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" ) library(modifile)
Manipulate filenames in R.
devtools::install_github("jensenlab/modifile")
The split_filename
function splits a filename into a path (directory location), the name of the file, and the file's extension.
split_filename("/path/to/file/myfile.fastq")
The join_filename
function does the opposite.
join_filename("/path/to/file", "myfile", "fastq")
All functions in modifile
are vectorized over their inputs.
split_filename(c("/path/to/file/myfile1.fastq", "/path/to/file/myfile2.fastq")) join_filename("/path/to/file", c("myfile1","myfile2"), "fastq")
A file's extensions includes all suffixes to allow for compressed files.
split_filename("file.fasta.gz")
The modify_filename
function can change the path, name, or extension of filenames.
test_filenames <- c("./file.fastq", "file.fq", "/path/to/file/file.fastq.gz") modify_filename(test_filenames, new_path="newdir") modify_filename(test_filenames, new_name="newfile") modify_filename(test_filenames, new_ext="bam")
Remove the path, name, or extension by setting the new value to an empty string.
modify_filename(test_filenames, new_ext="")
You can also add test before or after each part of the filename.
modify_filename("/path/file.ext", before_path="<BEFORE_PATH>", after_path="<AFTER_PATH>", before_name="<BEFORE_NAME>", after_name="<AFTER_NAME>", before_ext="<BEFORE_EXT>", after_ext="<AFTER_EXT>")
The after_path
test is treated as a subdirectory, and before_ext
is inserted after the .
but before the rest of the extension.
The concat_filenames
function joins two sets of filenames. By default, only the names of the files are joined.
concat_filenames("path1/name1.fastq", "path2/name2.fa.gz")
You can choose to join the path, name, extension or any combination. Setting the path
, name
, and ext
arguments to:
0
drops the part of the filename1
uses the part from filename1
2
uses the part from filename2
1+2
combines the part from filename1
and filename2
using the separator in sep
concat_filenames("path1/name1.fastq", "path2/name2.fa.gz", path=2, name=1+2, ext=1, sep="@")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.