[58c332]: / archives / RadETL / R / StandardIO.R

Download this file

69 lines (59 with data), 1.6 kB

 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Paste Functions..
pasteSep <- function(sep) {
function(...) {
paste(..., sep = sep)
}
}
# Paste String Lists...
pasteNormal = pasteSep("")
pasteSpacing = pasteSep(" ")
pastePath = pasteSep("/")
pasteSQL = pasteSep(".")
# Create directory...
createDir <- function(savePathRoot, path) {
dirPath <- Reduce(pastePath, c(savePathRoot, path))
if(!dir.exists(dirPath)) {
dir.create(path = dirPath, recursive = TRUE, mode = "0755")
msg <- c(Sys.time(), " -> Created Dir: ", dirPath)
print(Reduce(pasteNormal, msg))
}
}
# String equals Method,,
equals <- function(str1, str2) {
if(is.null(str1))
stop("NPE...")
else if(pmatch(str1, str2, nomatch = FALSE) == 1) TRUE else FALSE
}
# Covert DateTime format
getDateTime <- function(date, time) strptime(Reduce(pasteNormal, c(date, time)), format="%Y%m%d%H%M%OS")
# Convert Date format
getDate <- function(date) as.Date(date, format="%Y%m%d")
# Caculate during time..
getDiffTime <- function(before, after, units = "secs") {
options(digits = 3)
difftime(after, before, units = units)
}
as.float <- function(x, digits) {
options(digits = digits)
ret <- as.numeric(x)
options(digits = 1)
return(ret)
}
as.bigint <- function(x, scipen) {
options(scipen = scipen)
ret <- as.numeric(x)
return(ret)
}
getOS <- function() {
sysinf <- Sys.info()
if(!is.null(sysinf)) {
os <- sysinf['sysname']
os <- switch(os, Darwin = 'osx', Linux = 'Linux', 'cpm')
} else {
os <- .Platform$OS.type
if(grepl("^darwin", R.version$os)) os <- 'osx'
else if(grepl("^linux-gnu", R.version$os)) os <- 'Linux'
else os <- 'cpm'
}
return(os)
}