R/add_ext.R

Defines functions add_ext

# This script add desired extension if it's missing
# Unlike add_ext_read, this does not assume file exists (it can be a file to be written later)
#
# Internal function    
add_ext <- function(fo, ext) {
    # both inputs are mandatory
    if (missing(fo))
        stop('Output file (fo) is required!')
    if (missing(ext))
        stop('Expected file extension (ext) is required!')

    # if we actually didn't want an extension, don't do anything!
    if ( is.na( ext ) )
        return( fo )
    
    # test presence of expected extension (must be at the end)
    if ( ! grepl( paste0('\\.', ext, '$'), fo) ) {
        # add extension if it wasn't there already
        fo <- paste0(fo, '.', ext)
    }
    # return whatever fo is now
    return(fo)
}

Try the genio package in your browser

Any scripts or data that you put into this service are public.

genio documentation built on Jan. 7, 2023, 1:12 a.m.