File: import-internal-common.R

package info (click to toggle)
r-cran-memisc 0.99.31.8.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,136 kB
  • sloc: ansic: 5,117; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,467 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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)
}