R/import-internal-common.R

Defines functions iconv_list prettifyNames prettifyLab check.file

check.file <- function(filename,error=FALSE,warn=FALSE){
    if(!length(filename) || !nchar(filename)){
        if(error) stop("empty filename",call.=FALSE)
        else if(warn) warning("empty filename",call.=FALSE)
        return(FALSE)
    }
    if(file.access(filename,mode=0)== -1){
        if(warn || error){
            msg <- paste("cannot find",sQuote(basename(filename)),"in",sQuote(dirname(filename)))
            if(error) stop(msg,call.=FALSE)
            if(warn) warning(msg,call.=FALSE)
        }
        return(FALSE)
    }
    else return(TRUE)
}

prettifyLab <- function(x){
      if(!is.character(x)) return(x)
      nx <- names(x)
      x <- gsub("^[0-9]+[.][0-9]*\\s+","",x)
      x <- paste(
                  toupper(substring(x,1,1)),
                  tolower(substring(x,2)),
                  sep=""
                  )
      names(x) <- nx
         return(x)
    }

prettifyNames <- function(x){
      if(!length(x) || !is.atomic(x) && !is.list(x)) return(x)
      nx <- names(x)
      nx <- gsub("^[0-9]+[.][0-9]*\\s+","",nx)
      nx <- paste(
                  toupper(substring(nx,1,1)),
                  tolower(substring(nx,2)),
                  sep=""
                  )
      names(x) <- nx
      return(x)
    }

iconv_list <- function(x,encoded){
    iconv <- nzchar(encoded)
    if(iconv){
        ic <- sapply(x,is.character)
        if(any(ic))
            x[ic] <- lapply(x[ic],iconv,from=encoded)
    }
    return(x)
}

Try the memisc package in your browser

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

memisc documentation built on March 31, 2023, 7:29 p.m.