strip_extension-methods: Generic function to strip extension from file name, given a...

strip_extensionR Documentation

Generic function to strip extension from file name, given a FileFormat instance.

Description

Removes the file extension from a given file name based on the FileFormat specifications.

Usage

strip_extension(x, file_name)

## S4 method for signature 'FileFormat,character'
strip_extension(x, file_name)

Arguments

x

A FileFormat object specifying the format requirements

file_name

A character string specifying the file name to strip the extension from

Details

The function performs the following steps:

  1. If the file_name matches the header file format, it removes the header extension.

  2. If the file_name matches the data file format, it removes the data extension.

  3. If the file_name doesn't match either format, it throws an error.

Value

file_name without extension

A character string representing the file name without the extension

See Also

header_file, data_file for related file name manipulation

Examples

## Not run: 
fmt <- new("FileFormat", header_extension = "hdr", data_extension = "img")
strip_extension(fmt, "brain_scan.hdr")  # Returns "brain_scan"
strip_extension(fmt, "brain_scan.img")  # Returns "brain_scan"

## End(Not run)


bbuchsbaum/neuroim2 documentation built on Jan. 2, 2025, 3:38 p.m.