R/util.R

Defines functions dir.exists .trimleft .trimright .trim

###
### $Id: util.R 825 2014-06-25 22:06:03Z proebuck $
###


##-----------------------------------------------------------------------------
## Returns TRUE if path represents a directory; otherwise, FALSE.
dir.exists <- function(path) {
    ## Check arguments
    stopifnot(is.character(path) && length(path) == 1)

    ##-------------------------------------------------------------------------
    dirTest <- function(x) {
        !is.na(isdir <- file.info(x)$isdir) & isdir
    }

    ## Begin processing
    file.exists(path) && dirTest(path)
}


##-----------------------------------------------------------------------------
## Remove spaces from beginning of string.
.trimleft <- function(string) {
    stopifnot(is.character(string))

    gsub("^[[:space:]]+", "", string)
}


##-----------------------------------------------------------------------------
## Remove spaces from end of string.
.trimright <- function(string) {
    stopifnot(is.character(string))

    gsub("[[:space:]]+$", "", string)
}


##-----------------------------------------------------------------------------
## Remove spaces from both ends of string.
.trim <- function(string) {
    stopifnot(is.character(string))

    .trimright(.trimleft(string))
}

Try the SuperCurveGUI package in your browser

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

SuperCurveGUI documentation built on May 2, 2019, 5:43 p.m.