Debian Codegraph @

R/import-internal-common.R

raw
1 check.file <- function(filename,error=FALSE,warn=FALSE){
2 if(!length(filename) || !nchar(filename)){
3 if(error) stop("empty filename",call.=FALSE)
4 else if(warn) warning("empty filename",call.=FALSE)
5 return(FALSE)
6 }
7 if(file.access(filename,mode=0)== -1){
8 if(warn || error){
9 msg <- paste("cannot find",sQuote(basename(filename)),"in",sQuote(dirname(filename)))
10 if(error) stop(msg,call.=FALSE)
11 if(warn) warning(msg,call.=FALSE)
12 }
13 return(FALSE)
14 }
15 else return(TRUE)
16 }
17
18 prettifyLab <- function(x){
19 if(!is.character(x)) return(x)
20 nx <- names(x)
21 x <- gsub("^[0-9]+[.][0-9]*\\s+","",x)
22 x <- paste(
23 toupper(substring(x,1,1)),
24 tolower(substring(x,2)),
25 sep=""
26 )
27 names(x) <- nx
28 return(x)
29 }
30
31 prettifyNames <- function(x){
32 if(!length(x) || !is.atomic(x) && !is.list(x)) return(x)
33 nx <- names(x)
34 nx <- gsub("^[0-9]+[.][0-9]*\\s+","",nx)
35 nx <- paste(
36 toupper(substring(nx,1,1)),
37 tolower(substring(nx,2)),
38 sep=""
39 )
40 names(x) <- nx
41 return(x)
42 }
43
44 iconv_list <- function(x,encoded){
45 iconv <- nzchar(encoded)
46 if(iconv){
47 ic <- sapply(x,is.character)
48 if(any(ic))
49 x[ic] <- lapply(x[ic],iconv,from=encoded)
50 }
51 return(x)
52 }
53