├── .gitignore ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── ASCII.R ├── CEIL.R ├── CHR.R ├── DECODE.R ├── EDITDISTANCE.R ├── FLOOR.R ├── GREATEST.R ├── INITCAP.R ├── INSTR.R ├── LEAST.R ├── LENGTH.R ├── LPAD.R ├── LTRIM.R ├── NGRAM.R ├── OREPLACE.R ├── OTRANSLATE.R ├── POWER.R ├── REGR_INTERCEPT.R ├── ROUND.R ├── RPAD.R ├── RTRIM.R ├── SIGN.R ├── TO_CHAR.R ├── TO_NUMBER.R ├── TRUNC.R ├── as.data.frame.td.data.frame.R ├── as.td.data.frame.R ├── dim.td.data.frame.R ├── hist.td.data.frame.R ├── is.td.data.frame.R ├── is.td.expression.R ├── max.td.data.frame.R ├── mean.td.data.frame.R ├── median.td.data.frame.R ├── min.td.data.frame.R ├── on.R ├── ops.td.data.frame.R ├── predict.kmeans.R ├── print.td.data.frame.R ├── subset.td.data.frame.R ├── sum.td.data.frame.R ├── summary.td.data.frame.R ├── td.CalcMatrix.R ├── td.ExecR.R ├── td.bincode.R ├── td.binomial.R ├── td.binomialsign.R ├── td.call.sp.R ├── td.cor.R ├── td.cov.R ├── td.dagostino.pearson.R ├── td.data.frame.R ├── td.expression.R ├── td.f.oneway.R ├── td.factanal.R ├── td.freq.R ├── td.hist.R ├── td.join.R ├── td.kmeans.R ├── td.ks.R ├── td.lilliefors.R ├── td.merge.R ├── td.mode.R ├── td.mwnkw.R ├── td.nullreplace.R ├── td.overlap.R ├── td.quantiles.R ├── td.rank.R ├── td.recode.R ├── td.rescale.R ├── td.sample.R ├── td.shapiro.wilk.R ├── td.sigmoid.R ├── td.smirnov.R ├── td.solve.R ├── td.stats.R ├── td.t.paired.R ├── td.t.unpaired.R ├── td.t.unpairedi.R ├── td.tapply.R ├── td.values.R ├── td.wilcoxon.R ├── td.zscore.R ├── tdClose.R ├── tdConnect.R ├── tdMetadataDB.R ├── tdQuery.R ├── tdQueryUpdate.R ├── tdSave.R ├── teradataR-internal.R ├── z[.td.data.frame.R └── z[assign.td.data.frame.R ├── README.md ├── build └── teradataR_1.1.0.tar.gz ├── inst └── doc │ └── teradataR.pdf ├── man ├── INITCAP.Rd ├── LPAD.Rd ├── LTRIM.Rd ├── RPAD.Rd ├── RTRIM.Rd ├── as.data.frame.td.data.frame.Rd ├── as.td.data.frame.Rd ├── dim.td.data.frame.Rd ├── hist.td.data.frame.Rd ├── is.td.data.frame.Rd ├── max.td.data.frame.Rd ├── mean.td.data.frame.Rd ├── median.td.data.frame.Rd ├── min.td.data.frame.Rd ├── on.Rd ├── predict.kmeans.Rd ├── print.td.data.frame.Rd ├── subset.td.data.frame.Rd ├── sum.td.data.frame.Rd ├── summary.td.data.frame.Rd ├── td.CalcMatrix.Rd ├── td.ExecR.Rd ├── td.bincode.Rd ├── td.binomial.Rd ├── td.binomialsign.Rd ├── td.call.sp.Rd ├── td.cor.Rd ├── td.cov.Rd ├── td.dagostino.pearson.Rd ├── td.data.frame.Rd ├── td.f.oneway.Rd ├── td.factanal.Rd ├── td.freq.Rd ├── td.hist.Rd ├── td.join.Rd ├── td.kmeans.Rd ├── td.ks.Rd ├── td.lilliefors.Rd ├── td.merge.Rd ├── td.mode.Rd ├── td.mwnkw.Rd ├── td.nullreplace.Rd ├── td.overlap.Rd ├── td.quantiles.Rd ├── td.rank.Rd ├── td.recode.Rd ├── td.rescale.Rd ├── td.sample.Rd ├── td.shapiro.wilk.Rd ├── td.sigmoid.Rd ├── td.smirnov.Rd ├── td.solve.Rd ├── td.stats.Rd ├── td.t.paired.Rd ├── td.t.unpaired.Rd ├── td.t.unpairedi.Rd ├── td.tapply.Rd ├── td.values.Rd ├── td.wilcoxon.Rd ├── td.zscore.Rd ├── tdClose.Rd ├── tdConnect.Rd ├── tdMetadataDB.Rd ├── tdQuery.Rd ├── teradataR-package.Rd └── z[.td.data.frame.Rd └── test ├── .DS_Store ├── basicContract.txt ├── basicOperator.txt ├── setup.R ├── testCHR.R ├── testCalcMatrix.R ├── testDECODE.R ├── testExecR.R ├── testINITCAP.R ├── testINSTR.R ├── testLPAD.R ├── testLTRIM.R ├── testNGRAM.R ├── testOREPLACE.R ├── testOTRANSLATE.R ├── testOn.R ├── testPOWER.R ├── testRPAD.R ├── testRTRIM.R ├── testSIGN.R ├── testTO_CHAR.R ├── testTO_NUMBER.R ├── testTRUNC.R └── testUtil.R /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | 4 | # Example code in package build process 5 | *-Ex.R -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: teradataR 2 | Type: Package 3 | Title: Teradata R Package 4 | Version: 1.1.0 5 | Date: 2014-06-29 6 | Author: Todd Brye 7 | Maintainer: Alexander Bessonov 8 | Depends: R (>= 2.11.0) 9 | Suggests: RODBC (>= 1.3-9), RJDBC (>= 0.2-1) 10 | Description: This package allows you you access a Teradata database using the R language. It allows programmers familiar with R to analyze Teradata objects a lot like they would access a data frame object. 11 | License: GPL (>= 2) 12 | LazyLoad: yes 13 | Packaged: 2014-06-29 00:33:50 MSK; nonsleepr 14 | 15 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | export( 2 | as.data.frame.td.data.frame, 3 | as.td.data.frame, 4 | dim.td.data.frame, 5 | hist.td.data.frame, 6 | is.td.data.frame, 7 | max.td.data.frame, 8 | mean.td.data.frame, 9 | median.td.data.frame, 10 | min.td.data.frame, 11 | print.td.data.frame, 12 | sum.td.data.frame, 13 | summary.td.data.frame, 14 | td.bincode, 15 | td.binomial, 16 | td.binomialsign, 17 | td.call.sp, 18 | td.cor, 19 | td.cov, 20 | td.dagostino.pearson, 21 | td.data.frame, 22 | td.f.oneway, 23 | td.factanal, 24 | td.freq, 25 | td.hist, 26 | td.join, 27 | td.ks, 28 | td.lilliefors, 29 | td.merge, 30 | td.mode, 31 | td.mwnkw, 32 | td.nullreplace, 33 | td.overlap, 34 | td.quantiles, 35 | td.rank, 36 | td.recode, 37 | td.rescale, 38 | td.sample, 39 | td.shapiro.wilk, 40 | td.sigmoid, 41 | td.smirnov, 42 | td.solve, 43 | td.stats, 44 | td.t.paired, 45 | td.t.unpaired, 46 | td.t.unpairedi, 47 | td.values, 48 | td.wilcoxon, 49 | td.zscore, 50 | tdClose, 51 | tdConnect, 52 | tdMetadataDB, 53 | tdQuery, 54 | tdSave, 55 | td.kmeans, 56 | predict.kmeans, 57 | ASCII, 58 | CEIL, 59 | CHR, 60 | DECODE, 61 | EDITDISTANCE, 62 | FLOOR, 63 | INSTR, 64 | INITCAP, 65 | LENGTH, 66 | LPAD, 67 | LTRIM, 68 | NGRAM, 69 | OREPLACE, 70 | OTRANSLATE, 71 | RPAD, 72 | RTRIM, 73 | Ops.td.data.frame, 74 | Ops.td.expression, 75 | is.td.expression, 76 | GREATEST, 77 | LEAST, 78 | td.tapply, 79 | subset.td.data.frame, 80 | tdQueryUpdate, 81 | td.ExecR, 82 | on) 83 | S3method("[", td.data.frame) 84 | S3method("[<-", td.data.frame) 85 | -------------------------------------------------------------------------------- /R/ASCII.R: -------------------------------------------------------------------------------- 1 | ASCII <- function(x) { 2 | if (inherits(x, "td.data.frame")) { 3 | if (length(x) > 1) 4 | message("ASCII warning: td.data.frame 'x' has length > 1 using first element") 5 | 6 | val <- paste("ASCII(", .td.gencolumnexpr(x[1]), ")", sep = "") 7 | } else if (inherits(x, "td.expression")) 8 | val <- paste("ASCII(", x, ")", sep = "") else if (inherits(x, "character")) 9 | val <- paste("ASCII('", x, "')", sep = "") else stop("Invalid data type for 'x' in ASCII function") 10 | 11 | class(val) <- "td.expression" 12 | return(val) 13 | } 14 | -------------------------------------------------------------------------------- /R/CEIL.R: -------------------------------------------------------------------------------- 1 | CEIL <- function(x) { 2 | if (inherits(x, "td.data.frame")) { 3 | if (length(x) > 1) 4 | message("CEIL warning: td.data.frame 'x' has length > 1 using first element") 5 | 6 | val <- paste("CEIL(", .td.gencolumnexpr(x[1]), ")", sep = "") 7 | } else if (inherits(x, "td.expression") || inherits(x, "numeric")) 8 | val <- paste("CEIL(", x, ")", sep = "") else if (inherits(x, "character")) 9 | val <- paste("CEIL('", x, "')", sep = "") else stop("Invalid data type for 'x' in CEIL function") 10 | 11 | class(val) <- "td.expression" 12 | return(val) 13 | } 14 | 15 | # CEIL <- function(x) { if(inherits(x, 'td.data.frame')) { if(length(x) == 1) if(!is.null(attr(x, 'expressions'))) { 16 | # val <- paste('CEIL(', attr(x, 'expressions')[[names(x)]], ')', sep='') class(val) <- 'td.expression' return(val) } 17 | # else { val <- paste('CEIL(\'', names(x), '\')', sep='') class(val) <- 'td.expression' return(val) } else { 18 | # message('CEIL warning: td.data.frame 'x' has length > 1 using first element') val <- paste('CEIL(\'', names(x)[1], 19 | # '\')', sep='') class(val) <- 'td.expression' return(val) } } if(inherits(x, 'character') || 20 | # inherits(x,'td.expression')) { val <- paste('CEIL(', x, ')', sep='') class(val) <- 'td.expression' return(val) } } 21 | -------------------------------------------------------------------------------- /R/CHR.R: -------------------------------------------------------------------------------- 1 | CHR <- function(x) { 2 | if (inherits(x, "td.data.frame")) { 3 | if (length(x) > 1) 4 | message("CHR warning: td.data.frame 'x' has length > 1 using first element") 5 | 6 | val <- paste("CHR(", .td.gencolumnexpr(x[1]), ")", sep = "") 7 | } else if (inherits(x, "td.expression") || inherits(x, "numeric")) 8 | val <- paste("CHR(", x, ")", sep = "") else if (inherits(x, "character")) 9 | val <- paste("CHR('", x, "')", sep = "") else stop("Invalid data type for 'x' in CHR function") 10 | 11 | class(val) <- "td.expression" 12 | return(val) 13 | } 14 | -------------------------------------------------------------------------------- /R/DECODE.R: -------------------------------------------------------------------------------- 1 | DECODE <- function(x, default=NULL, ...) { 2 | simplePaste <- function(i) { 3 | if(inherits(i, "numeric")) { 4 | res <- as.numeric(paste(i)) 5 | } 6 | else { 7 | res <- paste("'",i,"'", sep="") 8 | } 9 | return(res) 10 | } 11 | params <- list(...) 12 | res <- lapply(params, simplePaste) 13 | res <- paste(res, collapse=",") 14 | if (inherits(x, "td.data.frame")) { 15 | if (length(x) > 1) { 16 | message("DECODE warning: td.data.frame 'x' has length > 1 using first element") 17 | } 18 | val <- paste("DECODE(", .td.gencolumnexpr(x[1]), ",", res, ",'", default, "')", sep = "") 19 | } 20 | else if (inherits(x, "td.expression") || inherits(x, "numeric")) { 21 | val <- paste("DECODE(", x, ",", res, ",'", default, "')", sep = "") 22 | } 23 | else if (inherits(x, "character")) { 24 | val <- paste("DECODE('", x, "'", ",", res, ",'", default, "')", sep = "") 25 | } 26 | else stop("Invalid data type for 'x' in DECODE function") 27 | 28 | class(val) <- "td.expression" 29 | return(val) 30 | } -------------------------------------------------------------------------------- /R/EDITDISTANCE.R: -------------------------------------------------------------------------------- 1 | EDITDISTANCE <- function(x, y) { 2 | if (inherits(x, "td.data.frame")) { 3 | if (length(x) > 1) 4 | message("EDITDISTANCE warning: td.data.frame 'x' has length > 1 using first element") 5 | 6 | xval <- .td.gencolumnexpr(x[1]) 7 | } else if (inherits(x, "td.expression")) 8 | xval <- x else if (inherits(x, "character")) 9 | xval <- paste("'", x, "'", sep = "") else stop("Invalid data type for 'x' in EDITDISTANCE function") 10 | 11 | if (inherits(y, "td.data.frame")) { 12 | if (length(y) > 1) 13 | message("EDITDISTANCE warning: td.data.frame 'y' has length > 1 using first element") 14 | 15 | yval <- .td.gencolumnexpr(y[1]) 16 | } else if (inherits(y, "td.expression")) 17 | yval <- y else if (inherits(y, "character")) 18 | yval <- paste("'", y, "'", sep = "") else stop("Invalid data type for 'y' in EDITDISTANCE function") 19 | 20 | 21 | val <- paste("EDITDISTANCE(", xval, ",", yval, ")", sep = "") 22 | 23 | class(val) <- "td.expression" 24 | return(val) 25 | } 26 | 27 | # EDITDISTANCE <- function(x, second_string=' ') { asTdExpr <- function(x) {class(x) <- 'td.expression'; return(x)} 28 | # efmt <- 'EDITDISTANCE(%s,%s)' if(inherits(x, 'td.data.frame')) { if(length(x) == 1) { if(!is.null(attr(x, 29 | # 'expressions'))) val <- attr(x, 'expressions')[[names(x)]] else val <- names(x) } else { message('EDITDISTANCE 30 | # warning: td.data.frame 'x' has length > 1 using first element') val <- names(x)[1] } return(asTdExpr(gettextf(efmt, 31 | # val, second_string))) } if(inherits(x, 'character') || inherits(x,'td.expression')) { 32 | # return(asTdExpr(paste('EDITDISTANCE(', x, ',', second_string, ')', sep=''))) } } 33 | -------------------------------------------------------------------------------- /R/FLOOR.R: -------------------------------------------------------------------------------- 1 | FLOOR <- function(x) { 2 | if (inherits(x, "td.data.frame")) { 3 | if (length(x) > 1) 4 | message("FLOOR warning: td.data.frame 'x' has length > 1 using first element") 5 | 6 | val <- paste("FLOOR(", .td.gencolumnexpr(x[1]), ")", sep = "") 7 | } else if (inherits(x, "td.expression") || inherits(x, "numeric")) 8 | val <- paste("FLOOR(", x, ")", sep = "") else if (inherits(x, "character")) 9 | val <- paste("FLOOR('", x, "')", sep = "") else stop("Invalid data type for 'x' in FLOOR function") 10 | 11 | class(val) <- "td.expression" 12 | return(val) 13 | } 14 | 15 | # FLOOR <- function(x) { asTdExpr <- function(x) {class(x) <- 'td.expression'; return(x)} if(inherits(x, 16 | # 'td.data.frame')) { if(length(x) == 1) if(!is.null(attr(x, 'expressions'))) return(asTdExpr(paste('FLOOR(', attr(x, 17 | # 'expressions')[[1]], ')', sep=''))) else return(asTdExpr(paste('FLOOR(\'', names(x), '\')', sep=''))) else { 18 | # message('FLOOR warning: td.data.frame 'x' has length > 1 using first element') if(any(names(attr(x,'expressions')) == 19 | # '1')) return(asTdExpr(paste('FLOOR(', attr(x, 'expressions')[[1]], ')', sep=''))) else 20 | # return(asTdExpr(paste('FLOOR(\'', names(x)[1], '\')', sep=''))) } } if(inherits(x, 'character') || inherits(x, 21 | # 'td.expression')) { return(asTdExpr(paste('FLOOR(', x, ')', sep=''))) } stop('Invalid data type supplied to FLOOR') } 22 | -------------------------------------------------------------------------------- /R/GREATEST.R: -------------------------------------------------------------------------------- 1 | GREATEST <- function(...) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | parms <- list(...) 8 | if (length(parms) > 10 || length(parms) == 0) 9 | stop("Error: GREATEST must take from 1-10 parameters") 10 | 11 | pfmt <- "GREATEST(%s)" 12 | inputs <- character(0) 13 | 14 | for (i in 1:length(parms)) { 15 | x <- parms[[i]] 16 | if (inherits(x, "td.data.frame")) { 17 | if (length(x) > 1) 18 | message("GREATEST warning: td.data.frame 'x' has length > 1 using first element") 19 | 20 | inputs[i] <- .td.gencolumnexpr(x[1]) 21 | } else if (inherits(x, "character")) 22 | inputs[i] <- paste("'", x, "'", sep = "") else if (inherits(x, "td.expression") || inherits(x, "numeric")) 23 | inputs[i] <- x else stop(gettextf("Invalid data type for parameter %d in GREATEST function", i)) 24 | } 25 | 26 | return(asTdExpr(gettextf(pfmt, paste(inputs, collapse = ",")))) 27 | } 28 | -------------------------------------------------------------------------------- /R/INITCAP.R: -------------------------------------------------------------------------------- 1 | INITCAP <- function(x) { 2 | #handles condition in which x is a td data frame 3 | if (inherits(x, "td.data.frame")) { 4 | if (length(x) > 1) 5 | message("INITCAP warning: td.data.frame 'x' has length > 1 using first element") 6 | 7 | #sets up query expression 8 | val <- paste("INITCAP(", .td.gencolumnexpr(x[1]), ")", sep = "") 9 | #handles condition in which x is a td expression or numeric 10 | } 11 | else if (inherits(x, "td.expression") || inherits(x, "numeric") || inherits(x, "character")) 12 | val <- paste("INITCAP(", x, ")", sep = "") 13 | else stop("Invalid data type for 'x' in INITCAP function") 14 | 15 | class(val) <- "td.expression" 16 | return(val) 17 | } -------------------------------------------------------------------------------- /R/INSTR.R: -------------------------------------------------------------------------------- 1 | INSTR <- function(x, y) { 2 | # check type of x 3 | if (inherits(x, "td.data.frame")) { 4 | if (length(x) > 1) 5 | message("INSTR warning: td.data.frame 'x' has length > 1 using first element") 6 | 7 | xval <- .td.gencolumnexpr(x[1]) 8 | } else if (inherits(x, "td.expression")) 9 | xval <- x else if (inherits(x, "character")) 10 | xval <- paste("'", x, "'", sep = "") else stop("Invalid data type for 'x' in INSTR function") 11 | 12 | # check type of y 13 | if (inherits(y, "td.data.frame")) { 14 | if (length(y) > 1) 15 | message("INSTR warning: td.data.frame 'y' has length > 1 using first element") 16 | 17 | yval <- .td.gencolumnexpr(y[1]) 18 | } else if (inherits(y, "td.expression")) 19 | yval <- y else if (inherits(y, "character")) 20 | yval <- paste("'", y, "'", sep = "") else stop("Invalid data type for 'y' in INSTR function") 21 | 22 | 23 | val <- paste("INSTR(", xval, ",", yval, ")", sep = "") 24 | 25 | class(val) <- "td.expression" 26 | return(val) 27 | } -------------------------------------------------------------------------------- /R/LEAST.R: -------------------------------------------------------------------------------- 1 | LEAST <- function(...) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | parms <- list(...) 8 | if (length(parms) > 10 || length(parms) == 0) 9 | stop("Error: LEAST must take from 1-10 parameters") 10 | 11 | pfmt <- "LEAST(%s)" 12 | inputs <- character(0) 13 | 14 | for (i in 1:length(parms)) { 15 | x <- parms[[i]] 16 | if (inherits(x, "td.data.frame")) { 17 | if (length(x) > 1) 18 | message("LEAST warning: td.data.frame 'x' has length > 1 using first element") 19 | 20 | inputs[i] <- .td.gencolumnexpr(x[1]) 21 | } else if (inherits(x, "character")) 22 | inputs[i] <- paste("'", x, "'", sep = "") else if (inherits(x, "td.expression") || inherits(x, "numeric")) 23 | inputs[i] <- x else stop(gettextf("Invalid data type for parameter %d in LEAST function", i)) 24 | } 25 | 26 | return(asTdExpr(gettextf(pfmt, paste(inputs, collapse = ",")))) 27 | } 28 | -------------------------------------------------------------------------------- /R/LENGTH.R: -------------------------------------------------------------------------------- 1 | LENGTH <- function(x) { 2 | if (inherits(x, "td.data.frame")) { 3 | if (length(x) > 1) 4 | message("LENGTH warning: td.data.frame 'x' has length > 1 using first element") 5 | 6 | val <- paste("LENGTH(", .td.gencolumnexpr(x[1]), ")", sep = "") 7 | } else if (inherits(x, "td.expression") || inherits(x, "numeric")) 8 | val <- paste("LENGTH(", x, ")", sep = "") else if (inherits(x, "character")) 9 | val <- paste("LENGTH('", x, "')", sep = "") else stop("Invalid data type for 'x' in LENGTH function") 10 | 11 | class(val) <- "td.expression" 12 | return(val) 13 | } 14 | 15 | # LENGTH <- function(x) { asTdExpr <- function(x) {class(x) <- 'td.expression'; return(x)} if(inherits(x, 16 | # 'td.data.frame')) { if(length(x) == 1) if(!is.null(attr(x, 'expressions'))) return(asTdExpr(paste('LENGTH(', attr(x, 17 | # 'expressions')[[names(x)]], ')', sep=''))) else return(asTdExpr(paste('LENGTH(\'', names(x), '\')', sep=''))) else 18 | # { message('LENGTH warning: td.data.frame 'x' has length > 1 using first element') return(asTdExpr(paste('LENGTH(\'', 19 | # names(x)[1], '\')', sep=''))) } } if(inherits(x, 'character') || inherits(x,'td.expression')) { 20 | # return(asTdExpr(paste('LENGTH(', x, ')', sep=''))) } } 21 | -------------------------------------------------------------------------------- /R/LPAD.R: -------------------------------------------------------------------------------- 1 | LPAD <- function(x, ilength, fill_string = " ") { 2 | #helper function to make sure input value is of correct type 3 | asTdExpr <- function(x) { 4 | class(x) <- "td.expression" 5 | return(x) 6 | } 7 | 8 | lfmt <- "LPAD(\"%s\",%d,\'%s\')" 9 | #handles conditions in which x is a td data frame 10 | if (inherits(x, "td.data.frame")) { 11 | if (length(x) == 1) { 12 | if (!is.null(attr(x, "expressions"))) 13 | val <- attr(x, "expressions")[[names(x)]] else val <- names(x) 14 | 15 | } else { 16 | message("LPAD warning: td.data.frame 'x' has length > 1 using first element") 17 | val <- names(x)[1] 18 | } 19 | 20 | return(asTdExpr(gettextf(lfmt, val, ilength, fill_string))) 21 | 22 | } 23 | #handles conditions in which x is a character or td expression 24 | if (inherits(x, "character") || inherits(x, "td.expression")) { 25 | return(asTdExpr(paste("LPAD(\"", x, "\",", ilength, ",", fill_string, ")", sep = " "))) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /R/LTRIM.R: -------------------------------------------------------------------------------- 1 | LTRIM <- function(x) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | lfmt <- "LTRIM(%s)" 8 | 9 | if (length(x) == 1) { 10 | if (!is.null(attr(x, "expressions"))) 11 | val <- attr(x, "expressions")[[names(x)]] else val <- names(x) 12 | 13 | } else { 14 | message("LTRIM warning: td.data.frame 'x' has length > 1 using first element") 15 | val <- names(x)[1] 16 | } 17 | return(asTdExpr(gettextf(lfmt, val))) 18 | } 19 | -------------------------------------------------------------------------------- /R/NGRAM.R: -------------------------------------------------------------------------------- 1 | NGRAM <- function(x, y, gram_length) { 2 | #helper function acts as a setter for class td.expression 3 | asTdExpr <- function(x) { 4 | class(x) <- "td.expression" 5 | return(x) 6 | } 7 | #set up base text 8 | ofmt <- "NGRAM(%s,%s,%d)" 9 | #determine datatype of parameters 10 | if (inherits(x, "td.data.frame") || inherits(y, "td.data.frame")) { 11 | if (length(x) == 1 && length(y) == 1) { 12 | if (!is.null(attr(x, "expressions")) && (!is.null(attr(y, "expressions")))) { 13 | val1 <- attr(x, "expressions")[[names(x)]] 14 | val2 <- attr(y, "expressions")[[names(y)]] 15 | } 16 | else { 17 | val1 <- names(x) 18 | val2 <- names(y) 19 | } 20 | } 21 | else { 22 | message("NGRAM warning: td.data.frame 'x' or 'y' has length > 1 using first element") 23 | val1 <- names(x)[1] 24 | val2 <- names(y)[1] 25 | } 26 | return(asTdExpr(gettextf(ofmt, val1, val2, gram_length))) 27 | 28 | } 29 | #check for other datatypes 30 | if (inherits(x, "character") || inherits(x, "td.expression") || inherits(y, "character") || inherits(y, "td.expression")) { 31 | return(asTdExpr(paste("NGRAM(", x, ",",y, ",", gram_length, ")", sep = ""))) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /R/OREPLACE.R: -------------------------------------------------------------------------------- 1 | OREPLACE <- function(x, search_char, replace_char) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | rfmt <- "OREPLACE(%s, %s, %s)" 8 | if (inherits(x, "td.data.frame")) { 9 | if (length(x) == 1 || length(y) == 1) { 10 | if (!is.null(attr(x, "expressions")) || !is.null(attr(search_char, "expressions")) || !is.null(attr(replace_char, "expressions"))) { 11 | val1 <- attr(x, "expressions")[[names(x)]] 12 | val2 <- attr(search_char, "expressions")[[names(search_char)]] 13 | val3 <- attr(replace_char, "expressions")[[names(replace_char)]] 14 | } 15 | else { 16 | val1 <- names(x) 17 | val2 <- names(search_char) 18 | val3 <- names(replace_char) 19 | } 20 | } 21 | else { 22 | message("OREPLACE warning: td.data.frame 'x' or 'search_string' or 'replace_string' has length > 1 using first element") 23 | val1 <- names(x)[1] 24 | val2 <- names(search_char)[1] 25 | val3 <- names(replace_char)[1] 26 | } 27 | 28 | return(asTdExpr(gettextf(rfmt, val1, val2, val3))) 29 | 30 | } 31 | 32 | if (inherits(x, "character") || inherits(x, "td.expression")) { 33 | return(asTdExpr(paste("OREPLACE(", val1, ", ", val2, ", ", val3, ")", sep = ""))) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /R/OTRANSLATE.R: -------------------------------------------------------------------------------- 1 | OTRANSLATE <- function(x, search_char, replace_char) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | ofmt <- "OTRANSLATE(%s,%s,%s)" 8 | if (inherits(x, "td.data.frame") && inherits(search_char, "td.data.frame") && inherits(replace_char, "td.data.frame")) { 9 | if (length(x) == 1 && length(search_char) == 1 && length(replace_char) == 1) { 10 | if (!is.null(attr(x, "expressions")) || !is.null(attr(search_char, "expressions")) || !is.null(attr(replace_char, "expressions"))) { 11 | val1 <- attr(x, "expressions")[[names(x)]] 12 | val2 <- attr(search_char, "expressions")[[names(search_char)]] 13 | val3 <- attr(replace_char, "expressions")[[names(replace_char)]] 14 | } 15 | else { 16 | val1 <- names(x) 17 | val2 <- names(search_char) 18 | val3 <- names(replace_char) 19 | } 20 | } 21 | } 22 | else { 23 | message("OTRANSLATE warning: td.data.frame 'x' or 'search_char' or 'replace_char' has length > 1 using first element") 24 | val1 <- names(x)[1] 25 | val2 <- names(search_char)[1] 26 | val3 <- names(replace_char)[1] 27 | } 28 | 29 | return(asTdExpr(gettextf(ofmt, val1, val2, val3))) 30 | 31 | if (inherits(x, "character") || inherits(x, "td.expression") || inherits(search_char, "character") || 32 | inherits(search_char,"td.expression") || inherits(replace_char, "character") || inherits(replace_char, "td.expression")) { 33 | return(asTdExpr(paste("OTRANSLATE(", x, ",", search_char, ",", replace_char, ")", sep = ""))) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /R/POWER.R: -------------------------------------------------------------------------------- 1 | POWER <- function(x, exponent = 1) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | pfmt <- "POWER(%s, %s)" 8 | if (inherits(x, "td.data.frame")) { 9 | if (length(x) == 1 || length(exponent) == 1) { 10 | if (!is.null(attr(x, "expressions"))) { 11 | val1 <- attr(x, "expressions")[[names(x)]] 12 | } 13 | else { 14 | val1 <- names(x) 15 | } 16 | if (!is.null(attr(exponent, "expressions"))) { 17 | val2 <- attr(exponent, "expressions")[[names(exponent)]] 18 | } 19 | else { 20 | val2 <- names(exponent) 21 | } 22 | } 23 | else { 24 | message("POWER warning: td.data.frame 'x' or 'exponent' has length > 1 using first element") 25 | val1 <- names(x)[1] 26 | val2 <- names(exponent)[1] 27 | } 28 | 29 | return(asTdExpr(gettextf(pfmt, val1, val2))) 30 | 31 | } 32 | 33 | if (inherits(x, "character") || inherits(x, "td.expression")) { 34 | return(asTdExpr(paste("POWER(", x, exponent, ")", sep = ""))) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /R/REGR_INTERCEPT.R: -------------------------------------------------------------------------------- 1 | REGR_INTERCEPT <- function(x, y) { 2 | if (inherits(x, "td.data.frame")) { 3 | if (length(x) > 1) 4 | message("REGR_INTERCEPT warning: td.data.frame 'x' has length > 1 using first element") 5 | 6 | xval <- .td.gencolumnexpr(x[1]) 7 | } else if (inherits(x, "td.expression")) 8 | xval <- x else if (inherits(x, "character")) 9 | xval <- paste("'", x, "'", sep = "") else stop("Invalid data type for 'x' in REGR_INTERCEPT function") 10 | 11 | if (inherits(y, "td.data.frame")) { 12 | if (length(y) > 1) 13 | message("REGR_INTERCEPT warning: td.data.frame 'y' has length > 1 using first element") 14 | 15 | yval <- .td.gencolumnexpr(y[1]) 16 | } else if (inherits(y, "td.expression")) 17 | yval <- y else if (inherits(y, "character")) 18 | yval <- paste("'", y, "'", sep = "") else stop("Invalid data type for 'y' in REGR_INTERCEPT function") 19 | 20 | 21 | val <- paste("REGR_INTERCEPT(", xval, ",", yval, ")", sep = "") 22 | 23 | class(val) <- "td.expression" 24 | return(val) 25 | } 26 | 27 | # CEIL <- function(x) { if(inherits(x, 'td.data.frame')) { if(length(x) == 1) if(!is.null(attr(x, 'expressions'))) { 28 | # val <- paste('CEIL(', attr(x, 'expressions')[[names(x)]], ')', sep='') class(val) <- 'td.expression' return(val) } 29 | # else { val <- paste('CEIL(\'', names(x), '\')', sep='') class(val) <- 'td.expression' return(val) } else { 30 | # message('CEIL warning: td.data.frame 'x' has length > 1 using first element') val <- paste('CEIL(\'', names(x)[1], 31 | # '\')', sep='') class(val) <- 'td.expression' return(val) } } if(inherits(x, 'character') || 32 | # inherits(x,'td.expression')) { val <- paste('CEIL(', x, ')', sep='') class(val) <- 'td.expression' return(val) } } 33 | -------------------------------------------------------------------------------- /R/ROUND.R: -------------------------------------------------------------------------------- 1 | ROUND <- function(x, places = 1) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | pfmt <- "ROUND(%s,%d)" 8 | if (inherits(x, "td.data.frame")) { 9 | if (length(x) == 1) { 10 | if (!is.null(attr(x, "expressions"))) 11 | val <- attr(x, "expressions")[[names(x)]] else val <- names(x) 12 | 13 | } else { 14 | message("ROUND warning: td.data.frame 'x' has length > 1 using first element") 15 | val <- names(x)[1] 16 | } 17 | 18 | return(asTdExpr(gettextf(pfmt, val, places))) 19 | 20 | } 21 | 22 | if (inherits(x, "character") || inherits(x, "td.expression")) { 23 | return(asTdExpr(paste("ROUND(", x, ",", places, ")", sep = ""))) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /R/RPAD.R: -------------------------------------------------------------------------------- 1 | RPAD <- function(x, ilength, fill_string = " ") { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | rfmt <- "RPAD(\"%s\",%d,\'%s\')" 8 | if (inherits(x, "td.data.frame")) { 9 | if (length(x) == 1) { 10 | if (!is.null(attr(x, "expressions"))) 11 | val <- attr(x, "expressions")[[names(x)]] else val <- names(x) 12 | 13 | } else { 14 | message("RPAD warning: td.data.frame 'x' has length > 1 using first element") 15 | val <- names(x)[1] 16 | } 17 | 18 | return(asTdExpr(gettextf(rfmt, val, ilength, fill_string))) 19 | 20 | } 21 | 22 | if (inherits(x, "character") || inherits(x, "td.expression")) { 23 | return(asTdExpr(paste("RPAD(\"", x, "\",", ilength, ",", fill_string, ")", sep = ""))) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /R/RTRIM.R: -------------------------------------------------------------------------------- 1 | RTRIM <- function(x) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | rfmt <- "RTRIM(%s)" 8 | if (inherits(x, "td.data.frame")) { 9 | if (length(x) == 1) { 10 | if (!is.null(attr(x, "expressions"))) 11 | val <- attr(x, "expressions")[[names(x)]] else val <- names(x) 12 | 13 | } else { 14 | message("RTRIM warning: td.data.frame 'x' has length > 1 using first element") 15 | val <- names(x)[1] 16 | } 17 | 18 | return(asTdExpr(gettextf(rfmt, val))) 19 | } 20 | } -------------------------------------------------------------------------------- /R/SIGN.R: -------------------------------------------------------------------------------- 1 | SIGN <- function(x) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | pfmt <- "SIGN(%s)" 8 | if (inherits(x, "td.data.frame")) { 9 | if (length(x) == 1) { 10 | if (!is.null(attr(x, "expressions"))) 11 | val <- attr(x, "expressions")[[names(x)]] else val <- names(x) 12 | 13 | } else { 14 | message("SIGN warning: td.data.frame 'x' has length > 1 using first element") 15 | val <- names(x)[1] 16 | } 17 | 18 | return(asTdExpr(gettextf(pfmt, val))) 19 | 20 | } 21 | 22 | if (inherits(x, "character") || inherits(x, "td.expression") || inherits(x, "numeric")) { 23 | return(asTdExpr(paste("SIGN(", x, ")", sep = ""))) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /R/TO_CHAR.R: -------------------------------------------------------------------------------- 1 | TO_CHAR <- function(x, format) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | tfmt <- "TO_CHAR(%s, %s)" 8 | if (inherits(x, "td.data.frame") || inherits(format, "td.data.frame")) { 9 | if (length(x) == 1 || length(format) == 1) { 10 | if (!is.null(attr(x, "expressions"))) { 11 | val1 <- attr(x, "expressions")[[names(x)]] 12 | } 13 | else { 14 | val1 <- names(x) 15 | } 16 | if (!is.null(attr(format, "expressions"))) { 17 | val2 <- attr(format, "expressions")[[names(format)]] 18 | } 19 | else { 20 | val2 <- names(format) 21 | } 22 | } 23 | else { 24 | message("TO_CHAR warning: td.data.frame 'x' or 'format' has length > 1 using first element") 25 | val1 <- names(x)[1] 26 | val2 <- names(format)[1] 27 | } 28 | 29 | return(asTdExpr(gettextf(tfmt, val1, val2))) 30 | 31 | } 32 | 33 | if (inherits(x, "character") || inherits(x, "td.expression")) { 34 | return(asTdExpr(paste("TO_CHAR(", x, format, ")", sep = ""))) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /R/TO_NUMBER.R: -------------------------------------------------------------------------------- 1 | TO_NUMBER <- function(x) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | pfmt <- "TO_NUMBER(%s)" 8 | if (inherits(x, "td.data.frame")) { 9 | if (length(x) == 1) { 10 | if (!is.null(attr(x, "expressions"))) 11 | val <- attr(x, "expressions")[[names(x)]] else val <- names(x) 12 | 13 | } else { 14 | message("TO_NUMBER warning: td.data.frame 'x' has length > 1 using first element") 15 | val <- names(x)[1] 16 | } 17 | 18 | return(asTdExpr(gettextf(pfmt, val))) 19 | 20 | } 21 | 22 | if (inherits(x, "character") || inherits(x, "td.expression")) { 23 | return(asTdExpr(paste("TO_NUMBER(", x, ")", sep = ""))) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /R/TRUNC.R: -------------------------------------------------------------------------------- 1 | TRUNC <- function(x, places = 1) { 2 | asTdExpr <- function(x) { 3 | class(x) <- "td.expression" 4 | return(x) 5 | } 6 | 7 | pfmt <- "TRUNC(%s,%d)" 8 | if (inherits(x, "td.data.frame")) { 9 | if (length(x) == 1) { 10 | if (!is.null(attr(x, "expressions"))) 11 | val <- attr(x, "expressions")[[names(x)]] else val <- names(x) 12 | 13 | } else { 14 | message("TRUNC warning: td.data.frame 'x' has length > 1 using first element") 15 | val <- names(x)[1] 16 | } 17 | 18 | return(asTdExpr(gettextf(pfmt, val, places))) 19 | 20 | } 21 | 22 | if (inherits(x, "character") || inherits(x, "td.expression")) { 23 | return(asTdExpr(paste("TRUNC(", x, ",", places, ")", sep = ""))) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /R/as.data.frame.td.data.frame.R: -------------------------------------------------------------------------------- 1 | as.data.frame.td.data.frame <- function(x, size = 100) { 2 | if (!length(names(x))) 3 | stop("td.data.frame contains no columns") 4 | query <- paste(.td.tdf2sql(x), "SAMPLE", size) 5 | return(tdQuery(query)) 6 | } 7 | 8 | -------------------------------------------------------------------------------- /R/as.td.data.frame.R: -------------------------------------------------------------------------------- 1 | as.td.data.frame <- function(x, ...) { 2 | if (inherits(x, "td.data.frame")) { 3 | args <- list(...) 4 | if (is.null(args[["tableName"]])) 5 | tbl <- deparse(substitute(x)) else tbl <- args[["tableName"]] 6 | 7 | if (!is.null(args[["database"]])) 8 | oDatabase <- args[["database"]] else oDatabase <- NULL 9 | 10 | oObj <- .td.object(tbl, oDatabase) 11 | selectText <- .td.tdf2sql(x) 12 | 13 | query <- gettextf("CREATE TABLE %s AS (%s) WITH DATA", oObj, selectText) 14 | df <- try(tdQueryUpdate(query)) 15 | if (length(df) == 1L && df == "No Data") 16 | 17 | return(td.data.frame(tbl, oDatabase)) else stop(gettextf("Error: %s", paste(df, collapse = ""))) 18 | } 19 | if (inherits(x, "data.frame")) { 20 | tbl <- deparse(substitute(x)) 21 | tdSave(x, tbl) 22 | return(td.data.frame(tbl)) 23 | } 24 | stop("Unable to convert object to td.data.frame") 25 | } 26 | 27 | -------------------------------------------------------------------------------- /R/dim.td.data.frame.R: -------------------------------------------------------------------------------- 1 | dim.td.data.frame <- function(x) { 2 | rows <- attr(x, "totalRows") 3 | c(rows, length(x)) 4 | } 5 | 6 | -------------------------------------------------------------------------------- /R/hist.td.data.frame.R: -------------------------------------------------------------------------------- 1 | hist.td.data.frame <- function(x, breaks = 10, ...) { 2 | oldmf <- par("mfrow") 3 | oldoma <- par("oma") 4 | oldmar <- par("mar") 5 | on.exit(par(mfrow = oldmf, oma = oldoma, mar = oldmar)) 6 | la <- length(x) 7 | mf <- if (la <= 1) 8 | c(1, 1) else if (la <= 2) 9 | c(2, 1) else if (la <= 4) 10 | c(2, 2) else if (la <= 6) 11 | c(2, 3) else if (la <= 9) 12 | c(3, 3) else if (la <= 12) 13 | c(3, 4) else c(4, 4) 14 | if (la > 16) { 15 | la <- 16 16 | warning("Only showing first 16 variables") 17 | } 18 | par(mfrow = mf) 19 | 20 | for (i in 1:la) { 21 | if (!is.null(attr(x[i], "expressions"))) 22 | fnc <- .td.objectIsNumeric2 else fnc <- .td.objectIsNumeric 23 | 24 | if (fnc(attr(x, "database"), attr(x, "tableName"), .td.gencolumnexpr(x[names(x)[i]]))) 25 | td.hist(x, names(x)[i], breaks) else { 26 | df <- td.freq(x, names(x)[i], plot = FALSE) 27 | rvec <- df[[4]] 28 | names(rvec) <- df[[3]] 29 | dotchart(rvec, xlab = paste("Frequencies for", names(x)[i])) 30 | } 31 | } 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /R/is.td.data.frame.R: -------------------------------------------------------------------------------- 1 | is.td.data.frame <- function(x) { 2 | inherits(x, "td.data.frame") 3 | } 4 | 5 | -------------------------------------------------------------------------------- /R/is.td.expression.R: -------------------------------------------------------------------------------- 1 | is.td.expression <- function(x) { 2 | inherits(x, "td.expression") 3 | } 4 | 5 | -------------------------------------------------------------------------------- /R/max.td.data.frame.R: -------------------------------------------------------------------------------- 1 | max.td.data.frame <- function(tdf, ...) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (!length(names(tdf))) 5 | stop("td.data.frame contains no columns") 6 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 7 | exprs <- attr(tdf, "expressions") 8 | 9 | wc <- "" 10 | if (!is.null(attr(tdf, "whereClause"))) 11 | wc <- paste("WHERE", attr(tdf, "whereClause")) 12 | 13 | cols <- character(0) 14 | for (i in 1:length(names(tdf))) { 15 | if (as.character(i) %in% names(exprs)) 16 | col <- gettextf("MAX(%s) AS xmax", .td.gencolumnexpr(tdf[i])) else col <- .td.genstats(names(tdf)[i], "max") 17 | 18 | cols[i] <- paste(col, as.character(i), sep = "") 19 | } 20 | 21 | query <- gettextf("SELECT %s FROM %s %s", paste(cols, collapse = ","), obj, wc) 22 | df <- try(tdQuery(query)) 23 | if (is.null(attr(df, "class"))) 24 | stop("Only defined on a td data frame with all numeric variables") 25 | return(max(df)) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /R/mean.td.data.frame.R: -------------------------------------------------------------------------------- 1 | mean.td.data.frame <- function(x, ...) { 2 | if (!is.td.data.frame(x)) 3 | stop("'x' is not a td data frame") 4 | if (!length(names(x))) 5 | stop("td.data.frame contains no columns") 6 | obj <- .td.object(attr(x, "tableName"), attr(x, "database")) 7 | meanVal <- double(0) 8 | exprs <- attr(x, "expressions") 9 | 10 | wc <- "" 11 | if (!is.null(attr(x, "whereClause"))) 12 | wc <- paste("WHERE", attr(x, "whereClause")) 13 | 14 | for (i in 1:length(names(x))) { 15 | if (as.character(i) %in% names(exprs)) 16 | col <- gettextf("AVG(%s) AS xmean", .td.gencolumnexpr(x[i])) else col <- .td.genstats(names(x)[i], "mean") 17 | 18 | query <- gettextf("SELECT %s FROM %s %s", col, obj, wc) 19 | df <- try(tdQuery(query)) 20 | if (is.null(attr(df, "class"))) { 21 | warning("argument is not numeric or logical: returning NA") 22 | meanVal[length(meanVal) + 1] <- NA 23 | } else meanVal[length(meanVal) + 1] <- as.numeric(df) 24 | names(meanVal)[length(meanVal)] <- names(x)[i] 25 | } 26 | return(meanVal) 27 | } 28 | 29 | -------------------------------------------------------------------------------- /R/median.td.data.frame.R: -------------------------------------------------------------------------------- 1 | median.td.data.frame <- function(x) { 2 | if (!is.td.data.frame(x)) 3 | stop("'x' is not a td data frame") 4 | if (length(x) != 1) 5 | stop("median can only be run against a td data frame of one column.") 6 | 7 | query <- paste(.td.genmedian(x, names(x))) 8 | df <- try(tdQuery(query)) 9 | return(as.numeric(df)) 10 | } 11 | 12 | -------------------------------------------------------------------------------- /R/min.td.data.frame.R: -------------------------------------------------------------------------------- 1 | min.td.data.frame <- function(tdf, ...) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (!length(names(tdf))) 5 | stop("td.data.frame contains no columns") 6 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 7 | exprs <- attr(tdf, "expressions") 8 | wc <- "" 9 | if (!is.null(attr(tdf, "whereClause"))) 10 | wc <- paste("WHERE", attr(tdf, "whereClause")) 11 | 12 | cols <- character(0) 13 | for (i in 1:length(names(tdf))) { 14 | if (as.character(i) %in% names(exprs)) 15 | col <- gettextf("MIN(%s) AS xmin", .td.gencolumnexpr(tdf[i])) else col <- .td.genstats(names(tdf)[i], "min") 16 | 17 | cols[i] <- paste(col, as.character(i), sep = "") 18 | } 19 | 20 | query <- gettextf("SELECT %s FROM %s %s", paste(cols, collapse = ","), obj, wc) 21 | df <- try(tdQuery(query)) 22 | if (is.null(attr(df, "class"))) 23 | stop("Only defined on a td data frame with all numeric variables") 24 | return(min(df)) 25 | } 26 | 27 | -------------------------------------------------------------------------------- /R/on.R: -------------------------------------------------------------------------------- 1 | on <- function(target=NULL, from=NULL, subQuery=NULL, partition=NULL, hash=NULL, order=NULL, local_order=NULL, null_order=NULL, dimension=NULL, as=NULL) { 2 | if(!is.null(subQuery)) { 3 | baseText <- paste("on %s%s%s%s", subQuery, "%s") 4 | } 5 | else { 6 | baseText <- "on %s%s%s%s%s" 7 | } 8 | if (grepl("select", target)) { 9 | if(!is.null(from)) { 10 | returnString <- gettextf(baseText, "(", target," from ", from, ")") 11 | } 12 | else { 13 | returnString <- gettextf(baseText, "(", target, ")", "", "") 14 | } 15 | } 16 | else { 17 | returnString <- gettextf(baseText, target, "", "", "", "","") 18 | } 19 | 20 | if(!is.null(as)) { 21 | returnString <- paste(returnString, .td.makeAs(as), sep="\n") 22 | } 23 | if (!is.null(partition)) { 24 | returnString <- paste( returnString, .td.makePartition(partition), sep = "\n") 25 | } 26 | if (!is.null(hash)) { 27 | returnString <- paste(returnString, .td.makeHash(hash), sep="\n") 28 | } 29 | if (!is.null(order)) { 30 | returnString <- paste(returnString, .td.makeOrder(order), sep="\n") 31 | } 32 | 33 | if (!is.null(local_order)) { 34 | returnString <- paste(returnString, .td.makeLocalOrder(null_order, local_order), sep="\n") 35 | } 36 | if (!is.null(dimension)) { 37 | returnString <- paste(returnString, .td.makeDimension(), sep="\n") 38 | } 39 | returnString <- gsub(";", "", returnString) 40 | return(returnString) 41 | } 42 | -------------------------------------------------------------------------------- /R/ops.td.data.frame.R: -------------------------------------------------------------------------------- 1 | Ops.td.data.frame <- function(e1, e2) { 2 | aparen <- bparen <- FALSE 3 | if (!missing(e1)) { 4 | da <- deparse(substitute(e1)) 5 | if (substr(da, 1, 1) == "(" && substr(da, nchar(da), nchar(da)) == ")") 6 | aparen <- TRUE 7 | } 8 | if (!missing(e2)) { 9 | db <- deparse(substitute(e2)) 10 | if (substr(db, 1, 1) == "(" && substr(db, nchar(db), nchar(db)) == ")") 11 | bparen <- TRUE 12 | } 13 | op = .Generic 14 | if (op == "%%") 15 | op = "mod" 16 | if (is.td.data.frame(e1)) 17 | aval <- paste("\"", names(e1), "\"", sep = "") 18 | if (missing(e2)) { 19 | if (aparen) 20 | aval <- paste("(", aval, ")", sep = "") 21 | val <- paste(aval, op) 22 | class(val) <- "td.expression" 23 | return(val) 24 | } 25 | if (is.td.data.frame(e2)) 26 | bval <- paste("\"", names(e2), "\"", sep = "") 27 | if (is.numeric(e1) || is.character(e1)) 28 | aval <- e1 29 | if (is.numeric(e2) || is.character(e2)) 30 | bval <- e2 31 | 32 | if (aparen) 33 | aval <- paste("(", aval, ")", sep = "") 34 | if (bparen) 35 | bval <- paste("(", bval, ")", sep = "") 36 | 37 | val <- paste(aval, op, bval) 38 | class(val) <- "td.expression" 39 | return(val) 40 | } 41 | -------------------------------------------------------------------------------- /R/predict.kmeans.R: -------------------------------------------------------------------------------- 1 | predict.kmeans <- function(object, newdata = NULL, oTable = "", oDatabase = "", ...) { 2 | if (is.data.frame(newdata)) { 3 | if (is.null(data)) 4 | return(object$cluster) 5 | cntrs <- object$centers 6 | cr <- nrow(cntrs) 7 | cnames <- colnames(cntrs) 8 | ndata <- newdata[, cnames, drop = FALSE] 9 | cids <- rep(NA, nrow(ndata)) 10 | ndata <- rbind(cntrs, ndata) 11 | dists <- numeric(cr) 12 | for (i in (cr + 1):nrow(ndata)) { 13 | for (j in 1:(cr)) dists[j] <- dist(ndata[c(j, i), ]) 14 | newc <- which.min(dists) 15 | if (length(newc) > 0) 16 | cids[i - cr] <- newc 17 | } 18 | return(as.numeric(cids)) 19 | } 20 | 21 | if (is.td.data.frame(newdata)) { 22 | parms <- pairlist(...) 23 | if (!nchar(oTable)) 24 | stop("When using a td data frame you must supply an 'oTable' parameter") 25 | oObj <- .td.object(oTable, oDatabase) 26 | kmeansText <- .td.genkmeans(newdata, object) 27 | query <- gettextf("CREATE TABLE %s AS (%s) WITH DATA", oObj, kmeansText) 28 | if (.td.objectExists(oObj)) 29 | stop(gettextf("Table %s already exists.", oObj)) 30 | df <- try(tdQueryUpdate(query)) 31 | if (length(df) == 1L && df == "No Data") 32 | return(td.data.frame(oTable, oDatabase)) else stop(gettextf("Error: %s", paste(df, collapse = ""))) 33 | } 34 | } 35 | 36 | .td.genkmeans <- function(tdf, km) { 37 | wc <- "" 38 | if (!is.null(attr(tdf, "whereClause"))) 39 | wc <- paste("WHERE", attr(tdf, "whereClause")) 40 | 41 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 42 | clusterId <- .td.genclusterid(as.data.frame(km$centers), "clusterID") 43 | query <- gettextf("SELECT %s,%s FROM %s %s", .td.gencolumnexpr(tdf), clusterId, obj, wc) 44 | return(query) 45 | } 46 | -------------------------------------------------------------------------------- /R/print.td.data.frame.R: -------------------------------------------------------------------------------- 1 | print.td.data.frame <- function(x, ...) { 2 | obj <- .td.object(attr(x, "tableName"), attr(x, "database")) 3 | rows <- attr(x, "sampleRows") 4 | cols <- length(names(x)) 5 | if (is.null(rows)) 6 | rows <- attr(x, "totalRows") 7 | cat(gettextf("Teradata table %s\n\n", obj)) 8 | cat("Columns\n") 9 | print(names(x)) 10 | if (!is.null(attr(x, "expressions"))) { 11 | cat("\n") 12 | cat("Transformed Column Expressions") 13 | exprs <- attr(x, "expressions") 14 | names(exprs) <- names(x)[as.integer(names(exprs))] 15 | cat("\n") 16 | print(paste(unclass(exprs), "AS", names(exprs))) 17 | } 18 | if (!is.null(attr(x, "whereClause"))) { 19 | cat("\n") 20 | cat("Condition\n") 21 | wc <- attr(x, "whereClause") 22 | print(wc) 23 | } 24 | cat(gettextf("\n%d rows\n", rows)) 25 | invisible(x) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /R/subset.td.data.frame.R: -------------------------------------------------------------------------------- 1 | subset.td.data.frame <- function(x, subset, select, drop = FALSE, ...) { 2 | if (!missing(subset)) { 3 | e <- substitute(subset) 4 | wc <- deparse(e) 5 | # r <- eval(e, x, parent.frame()) if (!is.logical(r)) stop(''subset' must evaluate to logical') r <- r & !is.na(r) 6 | } 7 | if (missing(select)) 8 | vars <- TRUE else { 9 | nl <- as.list(seq_along(x)) 10 | names(nl) <- names(x) 11 | vars <- eval(substitute(select), nl, parent.frame()) 12 | } 13 | 14 | if (exists("wc")) { 15 | y <- x[vars] 16 | wc <- gsub("==", "=", wc) 17 | wc <- gsub("&&", " AND ", wc) 18 | wc <- gsub("&", " AND ", wc) 19 | wc <- gsub("||", " OR ", wc, fixed = TRUE) 20 | wc <- gsub("|", " OR ", wc, fixed = TRUE) 21 | wc <- gsub("^", "**", wc, fixed = TRUE) 22 | wc <- gsub("%%", " MOD ", wc) 23 | wc <- gsub("\"", "'", wc, fixed = TRUE) 24 | wc <- gsub("%in%", " IN ", wc) 25 | wc <- gsub("c(", "(", wc, fixed = TRUE) 26 | 27 | if (!is.null(attr(y, "whereClause"))) 28 | wc <- paste(attr(y, "whereClause"), "AND", wc) 29 | 30 | attr(y, "whereClause") <- wc 31 | 32 | obj <- .td.object(attr(x, "tableName"), attr(x, "database")) 33 | query <- sprintf("SELECT CAST(COUNT(*) AS FLOAT) FROM %s WHERE %s", obj, wc) 34 | res <- try(tdQuery(query)) 35 | if (!is.data.frame(res)) { 36 | warning("Invalid subset expression.") 37 | return(x[vars]) 38 | } 39 | attr(y, "totalRows") <- as.numeric(res) 40 | return(y) 41 | } 42 | 43 | return(x[vars]) 44 | } 45 | -------------------------------------------------------------------------------- /R/sum.td.data.frame.R: -------------------------------------------------------------------------------- 1 | sum.td.data.frame <- function(tdf, ...) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (!length(names(tdf))) 5 | stop("td.data.frame contains no columns") 6 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 7 | sumVal <- 0 8 | exprs <- attr(tdf, "expressions") 9 | 10 | wc <- "" 11 | if (!is.null(attr(tdf, "whereClause"))) 12 | wc <- paste(" WHERE ", attr(tdf, "whereClause")) 13 | 14 | for (i in 1:length(names(tdf))) { 15 | if (as.character(i) %in% names(exprs)) 16 | query <- gettextf("SELECT SUM(%s) FROM %s %s", .td.gencolumnexpr(tdf[i]), obj, wc) else query <- gettextf("SELECT SUM(\"%s\") FROM %s %s", names(tdf)[i], obj, wc) 17 | df <- try(tdQuery(query)) 18 | if (is.null(attr(df, "class"))) 19 | stop("Only defined on a td data frame with all numeric variables") 20 | sumVal <- sumVal + as.numeric(df) 21 | } 22 | return(sumVal) 23 | } 24 | 25 | -------------------------------------------------------------------------------- /R/summary.td.data.frame.R: -------------------------------------------------------------------------------- 1 | summary.td.data.frame <- function(tdf, maxsum = 7, digits = max(3, getOption("digits") - 3), ...) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 5 | lst <- list() 6 | 7 | wc <- "" 8 | if (!is.null(attr(tdf, "whereClause"))) 9 | wc <- paste(" WHERE ", attr(tdf, "whereClause")) 10 | 11 | for (i in 1:length(names(tdf))) { 12 | cols <- paste(.td.genstats(names(tdf)[i], c("min", "max", "mean", "cnt")), collapse = ",") 13 | cnull <- .td.genvalues(names(tdf)[i]) 14 | cols <- paste(cols, ",", cnull[1]) 15 | query <- gettextf("SELECT %s FROM %s %s", paste(cols, collapse = ","), obj, wc) 16 | mmmn <- try(tdQuery(query)) 17 | if (is.data.frame(mmmn)) { 18 | # query <- .td.genmedian(tdf,names(tdf)[i]) med <- tdQuery(query) 19 | query <- .td.genquartiles(tdf, names(tdf)[i], mmmn[[4]]) 20 | quar <- tdQuery(query) 21 | vals <- c(mmmn[[1]], quar[[1]], quar[[3]], mmmn[[3]], quar[[2]], mmmn[[2]], if (mmmn[[5]] > 0) mmmn[[5]] else double(0)) 22 | names(vals) <- c("Min.", "1st Qu.", "Median", "Mean", "3rd Qu.", "Max", if (mmmn[[5]] > 0) "NA's" else character(0)) 23 | } else { 24 | vals <- c() 25 | names(vals) <- c() 26 | amt <- maxsum 27 | query <- gettextf("SELECT \"%s\", COUNT(*) as cnt FROM %s %s GROUP BY 1 ORDER BY 2 DESC", names(tdf)[i], obj, 28 | wc) 29 | charvals <- tdQuery(query) 30 | v <- charvals[[1]] 31 | cs <- charvals[[2]] 32 | 33 | if (any(is.na(v))) { 34 | vals <- c(sum(cs[is.na(v)])) 35 | names(vals) <- "NA's" 36 | amt <- amt - 1 37 | nullIndex = which(is.na(v)) 38 | v <- v[-nullIndex] 39 | cs <- cs[-nullIndex] 40 | # v <- v[-(length(v))] cs <- cs[-(length(cs))] 41 | } 42 | if (length(v) > amt) { 43 | amt <- amt - 1 44 | vals <- c(sum(cs[(amt + 1):length(v)]), vals) 45 | names(vals)[1] <- "(OTHER)" 46 | } 47 | if (amt > length(v)) 48 | amt = length(v) 49 | prevnm <- names(vals) 50 | vals <- c(cs[1:amt], vals) 51 | names(vals) <- c(as.character(v[1:amt]), prevnm) 52 | } 53 | lst[[length(lst) + 1]] <- vals 54 | } 55 | names(lst) <- names(tdf) 56 | nv <- length(tdf) 57 | nm <- names(tdf) 58 | lw <- numeric(nv) 59 | nr <- max(unlist(lapply(lst, NROW))) 60 | for (i in 1L:nv) { 61 | sms <- lst[[i]] 62 | lbs <- format(names(sms)) 63 | sms <- paste(lbs, ":", format(sms, digits = digits), " ", sep = "") 64 | lw[i] <- nchar(lbs[1L], type = "w") 65 | length(sms) <- nr 66 | lst[[i]] <- sms 67 | } 68 | z <- unlist(lst, use.names = TRUE) 69 | dim(z) <- c(nr, nv) 70 | blanks <- paste(character(max(lw) + 2L), collapse = " ") 71 | pad <- floor(lw - nchar(nm, type = "w")/2) 72 | nm <- paste(substring(blanks, 1, pad), nm, sep = "") 73 | dimnames(z) <- list(rep.int("", nr), nm) 74 | attr(z, "class") <- c("table") 75 | z 76 | } 77 | 78 | -------------------------------------------------------------------------------- /R/td.CalcMatrix.R: -------------------------------------------------------------------------------- 1 | td.CalcMatrix <- function(selectPhrase=string, ons=string, phase=NULL, calctype=NULL, output=NULL, null_handling=NULL, optional_operators=NULL, as=NULL) { 2 | 3 | ons <- unlist(ons) 4 | ons <- paste(ons, sep="", collapse="\n") 5 | using <- .td.usingClause(phase=phase, calctype=calctype, output=output, null_handling=null_handling) 6 | queryText <- paste(selectPhrase, "(\n", ons, using, ") ", optional_operators, " as ", as, ";") 7 | 8 | print(queryText) 9 | return(queryText) 10 | } 11 | -------------------------------------------------------------------------------- /R/td.ExecR.R: -------------------------------------------------------------------------------- 1 | td.ExecR <- function(selectPhrase=string, ons=list(), returns=NULL, contract=NULL, operator=string, optional_operators=NULL) { 2 | ons<- unlist(ons) 3 | ons <- paste(ons, sep="", collapse="\n") 4 | using <- .td.usingClause(returns=returns, contract=contract, operator=operator) 5 | queryText <- paste(selectPhrase, "(\n", ons, "\n", using, optional_operators, "\n) as db;") 6 | 7 | return(queryText) 8 | } -------------------------------------------------------------------------------- /R/td.bincode.R: -------------------------------------------------------------------------------- 1 | td.bincode <- function(tdf, col, oTable, oDatabase = "", bins = 10) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 5 | oObj <- .td.object(oTable, oDatabase) 6 | nm <- names(tdf) 7 | nm <- nm[-(match(col, nm))] 8 | if (!(col %in% names(tdf))) 9 | stop(gettextf("Column %s not found in td.data.frame", col)) 10 | wc <- "" 11 | if (!is.null(attr(tdf, "whereClause"))) 12 | wc <- paste(" WHERE ", attr(tdf, "whereClause")) 13 | nms <- paste(rep(gettextf("\"%s\"", nm)), collapse = ",") 14 | colexpr <- .td.gencolumnexpr(tdf[col]) 15 | binText <- .td.genbin(colexpr, bins = bins, as = col) 16 | nms <- paste(nms, ",", binText, collapse = ",") 17 | query <- gettextf("CREATE TABLE %s AS (SELECT %s FROM %s, (%s) A %s) WITH DATA", oObj, nms, obj, gettextf("SELECT %s FROM %s %s", 18 | paste(.td.genstats(colexpr, c("min", "max")), collapse = ","), obj, wc), wc) 19 | if (.td.objectExists(oObj)) 20 | stop(gettextf("Table %s already exists.", oObj)) 21 | df <- try(tdQueryUpdate(query)) 22 | if (length(df) == 1L && df == "No Data") 23 | return(td.data.frame(oTable, oDatabase)) else stop(gettextf("Error: %s", paste(df, collapse = ""))) 24 | stop(gettextf("Error: %s", paste(df, collapse = ""))) 25 | } 26 | 27 | -------------------------------------------------------------------------------- /R/td.binomial.R: -------------------------------------------------------------------------------- 1 | td.binomial <- function(tdf, first, second, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(first) || missing(second) || !nchar(first) || !nchar(second)) 5 | stop("'first' and 'second are required parameters.") 6 | if (length(first) > 1L || length(second) > 1L) 7 | warning("Multiple dimension values not allowed for 'first' or 'second'. Using only first element.") 8 | if (thresh <= 0 || thresh >= 1) 9 | stop("'thresh' value must be greater than 0 and less than 1.") 10 | query <- .td.genbinomial(tdf, first[1], second[1]) 11 | df <- tdQuery(query) 12 | return(df) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/td.binomialsign.R: -------------------------------------------------------------------------------- 1 | td.binomialsign <- function(tdf, column, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(column) || !nchar(column)) 5 | stop("No 'column' specified.") 6 | if (thresh <= 0 || thresh >= 1) 7 | stop("'thresh' value must be greater than 0 and less than 1.") 8 | query <- .td.genbinomialsign(tdf, column) 9 | df <- tdQuery(query) 10 | return(df) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /R/td.call.sp.R: -------------------------------------------------------------------------------- 1 | td.call.sp <- function() { 2 | maxDisplay <- 10 3 | currentIndex <- 1 4 | df <- tdQuery(paste("SELECT CAST(databasename AS VARCHAR(30)),CAST(tablename AS VARCHAR(30)) FROM DBC.TABLESX WHERE TableKind = 'P' ", 5 | "ORDER BY LastAlterTimeStamp DESC")) 6 | if (nrow(df) < maxDisplay) 7 | maxDisplay <- nrow(df) 8 | done <- FALSE 9 | while (!done) { 10 | cat("\n") 11 | for (i in currentIndex:(currentIndex + maxDisplay - 1)) cat(gettextf("%d) %s.%s\n", i, df[i, 1], df[i, 2])) 12 | cat(gettextf("\nShowing %d - %d of %d\n", currentIndex, currentIndex + maxDisplay - 1, nrow(df))) 13 | cat(gettext("Enter # to run stored procedure, (n)ext, (p)revious, or (q)uit: ")) 14 | ans <- readLines(, 1) 15 | 16 | if (ans == "q") 17 | break 18 | if (ans == "n") { 19 | currentIndex <- currentIndex + maxDisplay 20 | if (currentIndex > nrow(df)) 21 | currentIndex <- 1 22 | } 23 | if (ans == "p") { 24 | currentIndex <- currentIndex - maxDisplay 25 | if (currentIndex < 1) 26 | currentIndex <- 1 27 | } 28 | 29 | old.warn <- getOption("warn") 30 | options(warn = -1) 31 | idx <- as.numeric(ans) 32 | options(warn = old.warn) 33 | if (!is.na(idx) && (idx >= currentIndex && idx <= (currentIndex + maxDisplay - 1))) { 34 | obj <- .td.object(df[idx, 2], df[idx, 1]) 35 | qry <- gettextf(paste("SELECT CAST(ColumnName AS VARCHAR(30)), CAST(ColumnType AS VARCHAR(10)),CommentString FROM DBC.COLUMNSX ", 36 | "WHERE DatabaseName = '%s' and TableName = '%s' ORDER BY ColumnId", sep = ""), df[idx, 1], df[idx, 2]) 37 | 38 | df2 <- tdQuery(qry) 39 | parms <- character(0) 40 | ptypes <- character(0) 41 | for (i in 1:nrow(df2)) { 42 | if (is.na(df2[i, 3]) || !nchar(df2[i, 3])) 43 | cat(gettextf("Enter value for %s: ", df2[i, 1])) else cat(gettextf("Enter value for %s(%s): ", df2[i, 1], df2[i, 3])) 44 | ans <- readLines(, 1) 45 | parms[length(parms) + 1] <- ans 46 | ptypes[length(ptypes) + 1] <- as.character(df2[i, 2]) 47 | } 48 | td.numeric <- c("I", "F", "D", "I1", "I2") 49 | 50 | for (i in 1:length(parms)) if (!ptypes[i] %in% td.numeric) 51 | parms[i] <- gettextf("'%s'", parms[i]) 52 | plist <- paste(parms, collapse = ",") 53 | dfsp <- try(tdQuery(gettextf("CALL %s(%s)", obj, plist))) 54 | invisible(dfsp) 55 | } 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /R/td.cor.R: -------------------------------------------------------------------------------- 1 | td.cor <- function(tdf) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("td.cor requires a td.data.frame") 4 | if (!length(names(tdf))) 5 | stop("td.data.frame contains no columns") 6 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 7 | wc <- "" 8 | if (!is.null(attr(tdf, "whereClause"))) 9 | wc <- paste(" WHERE ", attr(tdf, "whereClause")) 10 | v <- names(tdf) 11 | vlen <- length(v) 12 | if (vlen < 2) { 13 | corMat <- matrix(1, 1, 1, dimnames = list(v, v)) 14 | corMat[] <- 1 15 | return(corMat) 16 | } 17 | a <- c() 18 | for (i in 1:(vlen - 1)) for (j in (i + 1):vlen) # a <- c(a,paste('CORR(',v[i],',',v[j],')',sep='')) 19 | a <- c(a, paste("CORR(", .td.gencolumnexpr(tdf[v[i]]), ",", .td.gencolumnexpr(tdf[v[j]]), ")", sep = "")) 20 | query <- gettextf("SELECT %s FROM %s %s", paste(a, collapse = ","), obj, wc) 21 | df <- try(tdQuery(query)) 22 | if (is.null(attr(df, "class"))) 23 | stop("'x' must be numeric") 24 | corMat <- matrix(1:(vlen * vlen), vlen, vlen, dimnames = list(v, v)) 25 | corMat[] <- 1 26 | idx <- 1 27 | for (i in 1:(vlen - 1)) for (j in (i + 1):vlen) { 28 | corMat[j, i] <- corMat[i, j] <- df[[idx]] 29 | idx <- idx + 1 30 | } 31 | return(corMat) 32 | } 33 | 34 | -------------------------------------------------------------------------------- /R/td.cov.R: -------------------------------------------------------------------------------- 1 | td.cov <- function(tdf) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("td.cov requires a td.data.frame") 4 | if (!length(names(tdf))) 5 | stop("td.data.frame contains no columns") 6 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 7 | wc <- "" 8 | if (!is.null(attr(tdf, "whereClause"))) 9 | wc <- paste(" WHERE ", attr(tdf, "whereClause")) 10 | v <- names(tdf) 11 | vlen <- length(v) 12 | a <- c() 13 | for (i in 1:vlen) for (j in i:vlen) a <- c(a, paste("COVAR_POP(", .td.gencolumnexpr(tdf[v[i]]), ",", .td.gencolumnexpr(tdf[v[j]]), 14 | ")", sep = "")) 15 | query <- sprintf("SELECT %s FROM %s %s", paste(a, collapse = ","), obj, wc) 16 | df <- try(tdQuery(query)) 17 | if (is.null(attr(df, "class"))) 18 | stop("'x' must be numeric") 19 | covMat <- matrix(1:(vlen * vlen), vlen, vlen, dimnames = list(v, v)) 20 | idx <- 1 21 | for (i in 1:vlen) for (j in i:vlen) { 22 | covMat[j, i] <- covMat[i, j] <- df[[idx]] 23 | idx <- idx + 1 24 | } 25 | return(covMat) 26 | } 27 | 28 | -------------------------------------------------------------------------------- /R/td.dagostino.pearson.R: -------------------------------------------------------------------------------- 1 | td.dagostino.pearson <- function(tdf, col, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col) || !nchar(col)) 5 | stop("'col' not specified.") 6 | if (thresh <= 0 || thresh >= 1) 7 | stop("'thresh' value must be greater than 0 and less than 1.") 8 | query <- .td.gendagopearson(tdf, col, thresh) 9 | df <- tdQuery(query) 10 | return(df) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /R/td.data.frame.R: -------------------------------------------------------------------------------- 1 | td.data.frame <- function(table, database = "") { 2 | if (missing(database) || is.null(database) || nchar(database) == 0) 3 | obj <- gettextf("\"%s\"", table) else obj <- gettextf("\"%s\".\"%s\"", database, table) 4 | query <- gettextf("SELECT * FROM %s SAMPLE 0", obj) 5 | res <- try(tdQuery(query)) 6 | if (is.null(attr(res, "class"))) { 7 | res <- data.frame(stringsAsFactors = FALSE) 8 | attr(res, "totalRows") <- 0 9 | warning("Teradata table not found. Result is empty data frame.") 10 | } else { 11 | query <- sprintf("SELECT CAST(COUNT(*) AS FLOAT) FROM %s", obj) 12 | res2 <- try(tdQuery(query)) 13 | attr(res, "totalRows") <- as.numeric(res2) 14 | } 15 | attr(res, "class") <- c("td.data.frame") 16 | attr(res, "tableName") <- table 17 | if (!is.null(database) && !missing(database) && nchar(database) > 0) 18 | attr(res, "database") <- database else { 19 | res2 <- try(tdQuery("SELECT DATABASE")) 20 | if (!is.null(attr(res2, "class"))) 21 | attr(res, "database") <- as.character(res2[[1]]) 22 | } 23 | return(res) 24 | } 25 | 26 | -------------------------------------------------------------------------------- /R/td.expression.R: -------------------------------------------------------------------------------- 1 | Ops.td.expression <- function(e1, e2) { 2 | aparen <- bparen <- FALSE 3 | if (!missing(e1)) { 4 | da <- deparse(substitute(e1)) 5 | if (substr(da, 1, 1) == "(" && substr(da, nchar(da), nchar(da)) == ")") 6 | aparen <- TRUE 7 | } 8 | if (!missing(e2)) { 9 | db <- deparse(substitute(e2)) 10 | if (substr(db, 1, 1) == "(" && substr(db, nchar(db), nchar(db)) == ")") 11 | bparen <- TRUE 12 | } 13 | op = .Generic 14 | if (op == "%%") 15 | op = "mod" 16 | if (is.td.data.frame(e1)) 17 | aval <- paste("\"", names(e1), "\"", sep = "") 18 | if (is.numeric(e1) || is.character(e1) || is.td.expression(e1)) 19 | aval <- e1 20 | if (missing(e2)) { 21 | if (aparen) 22 | aval <- paste("(", aval, ")", sep = "") 23 | val <- paste(aval, op) 24 | class(val) <- "td.expression" 25 | return(val) 26 | } 27 | if (is.td.data.frame(e2)) 28 | bval <- paste("\"", names(e2), "\"", sep = "") 29 | if (is.numeric(e2) || is.character(e2) || is.td.expression(e2)) 30 | bval <- e2 31 | 32 | if (aparen) 33 | aval <- paste("(", aval, ")", sep = "") 34 | if (bparen) 35 | bval <- paste("(", bval, ")", sep = "") 36 | 37 | val <- paste(aval, op, bval) 38 | class(val) <- "td.expression" 39 | return(val) 40 | } 41 | 42 | # 43 | -------------------------------------------------------------------------------- /R/td.f.oneway.R: -------------------------------------------------------------------------------- 1 | td.f.oneway <- function(tdf, col1, col2, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col1) || !nchar(col1)) 5 | stop("'col1' not specified.") 6 | if (missing(col2) || !length(col2)) 7 | stop("'col2' not specified.") 8 | if (thresh <= 0 || thresh >= 1) 9 | stop("'thresh' value must be greater than 0 and less than 1.") 10 | query <- .td.genfway(tdf, col1, col2, thresh) 11 | df <- tdQuery(query) 12 | return(df) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/td.factanal.R: -------------------------------------------------------------------------------- 1 | td.factanal <- function(tdf, ...) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | df <- td.cov(tdf) 5 | return(factanal(covmat = df, ...)) 6 | } 7 | 8 | -------------------------------------------------------------------------------- /R/td.freq.R: -------------------------------------------------------------------------------- 1 | td.freq <- function(tdf, col, plot = TRUE, ...) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col)) { 5 | nm <- names(tdf)[1] 6 | col <- .td.gencolumnexpr(tdf[names(tdf)[1]]) 7 | } else { 8 | nm <- col 9 | col <- .td.gencolumnexpr(tdf[col]) 10 | } 11 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 12 | query <- .td.genfreq(tdf, col) 13 | df <- try(tdQuery(query)) 14 | if (is.null(attr(df, "class"))) 15 | stop("Error retrieving frequency values from table.") 16 | if (plot == TRUE) { 17 | ttl <- gettextf("Frequency of %s", nm) 18 | xTbl <- as.table(df[[4]], df[[3]]) 19 | names(xTbl) <- df[[3]] 20 | barplot(xTbl, col = "dark red", xlab = col, ylab = "Counts", main = ttl) 21 | invisible(df) 22 | } else return(df) 23 | } 24 | 25 | -------------------------------------------------------------------------------- /R/td.hist.R: -------------------------------------------------------------------------------- 1 | td.hist <- function(tdf, col, breaks = 10, plot = TRUE, ...) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col)) { 5 | nm <- names(tdf)[1] 6 | col <- .td.gencolumnexpr(tdf[names(tdf)[1]]) 7 | } else { 8 | nm <- col 9 | col <- .td.gencolumnexpr(tdf[col]) 10 | } 11 | 12 | query <- .td.genhist(tdf, col, breaks) 13 | df <- try(tdQuery(query)) 14 | if (is.null(attr(df, "class"))) 15 | stop("'col' must be a numeric column") 16 | minBin <- df$xbin[1] 17 | maxBin <- df$xbin[nrow(df)] 18 | wid <- df$xend[1] - df$xbeg[1] 19 | brks <- seq(df$xbeg[1], by = wid, length.out = maxBin + 1) 20 | cnts <- rep(0, maxBin - 1) 21 | for (i in 1:nrow(df)) cnts[df$xbin[i]] <- df$xcnt[i] 22 | dens <- cnts/sum(cnts) 23 | myHist <- list(brks, cnts, dens, dens) 24 | names(myHist) <- c("breaks", "counts", "intensities", "density") 25 | attr(myHist, "class") <- "histogram" 26 | if (plot) 27 | try(plot(myHist, main = paste("Histogram of", col), col = "orange", ...)) else return(myHist) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /R/td.join.R: -------------------------------------------------------------------------------- 1 | td.join <- function(tdf1, tdf2, oTable = "newJoinTable", oDatabase = "", index1 = "", index2 = "", joinType = "inner") { 2 | oObj <- .td.object(oTable, oDatabase) 3 | if (missing(index1)) 4 | index1 <- .td.getPrimaryIndicies(tdf1) 5 | if (missing(index2)) 6 | index2 <- .td.getPrimaryIndicies(tdf2) 7 | if (length(index1) != length(index2)) 8 | stop("Index values to join on do not match.") 9 | jtypes <- c("inner", "left outer", "right outer", "full outer") 10 | tlist <- paste(jtypes, collapse = ",") 11 | if (!joinType %in% jtypes) 12 | stop(gettextf("Unknown 'joinType'. Must be one of %s", tlist)) 13 | joinText <- .td.genjoin(tdf1, tdf2, index1, index2, joinType) 14 | if (.td.objectExists(oObj)) 15 | stop(gettextf("Table %s already exists.", oObj)) 16 | query <- gettextf("CREATE TABLE %s AS (%s) WITH DATA", oObj, joinText) 17 | df <- try(tdQueryUpdate(query)) 18 | if (length(df) == 1L && df == "No Data") 19 | return(td.data.frame(oTable, oDatabase)) else stop(gettextf("Error: %s", paste(df, collapse = ""))) 20 | } 21 | 22 | -------------------------------------------------------------------------------- /R/td.kmeans.R: -------------------------------------------------------------------------------- 1 | td.kmeans <- function(x, centers, iter.max = 10, nstart = 1) { 2 | if (!is.td.data.frame(x)) 3 | stop("'x' is not a td data frame") 4 | if (length(centers) != 1L) 5 | stop("Only single numeric value allowed for 'centers'") 6 | if (!length(names(x))) 7 | stop("td.data.frame contains no columns") 8 | obj <- .td.object(attr(x, "tableName"), attr(x, "database")) 9 | wc <- "" 10 | if (!is.null(attr(x, "whereClause"))) 11 | wc <- paste(" WHERE ", attr(x, "whereClause")) 12 | ac <- "" 13 | if (!is.null(attr(x, "whereClause"))) 14 | ac <- paste(" AND ", attr(x, "whereClause")) 15 | 16 | nms <- paste(gettextf("\"%s\"", names(x)), collapse = ",") 17 | maxD <- 0 18 | for (i in 1:nstart) { 19 | testClusters <- tdQuery(gettextf("SELECT DISTINCT %s FROM %s %s SAMPLE %d", nms, obj, wc, centers)) 20 | curD <- 0 21 | for (j in 1:centers - 1) { 22 | for (k in (j + 1):centers) curD <- curD + sum(dist(testClusters[c(j, k), ])) 23 | } 24 | if (curD > maxD) { 25 | maxD <- curD 26 | initClusters <- testClusters 27 | } 28 | } 29 | if (centers == 1L || nrow(initClusters) < centers) 30 | iter <- iter.max + 1 else iter <- 1 31 | 32 | while (iter <= iter.max) { 33 | caseText <- .td.genclusterid(initClusters) 34 | sText <- paste(gettextf("SUM(CAST(\"%s\" AS FLOAT))/COUNT(*) AS \"%s\"", names(x), names(x)), collapse = ",") 35 | query <- gettextf("SELECT %s,%s FROM %s %s GROUP BY 1 ORDER BY 1", caseText, sText, obj, wc) 36 | newClusters <- try(tdQuery(query)) 37 | if (!is.data.frame(newClusters)) 38 | stop("Error processing request...try lower number of centers.") 39 | initClusters <- newClusters[-1] 40 | newCaseText <- .td.genclusterid(initClusters, "newClusterID") 41 | query <- gettextf("SELECT COUNT(*) FROM (SELECT %s, %s FROM %s WHERE clusterID <> newClusterID %s) A", caseText, 42 | newCaseText, obj, ac) 43 | switched <- try(tdQuery(query)) 44 | if (!is.data.frame(switched)) 45 | break 46 | if (!switched[1]) 47 | iter <- iter.max 48 | 49 | iter <- iter + 1 50 | } 51 | 52 | caseText <- .td.genclusterid(initClusters) 53 | query <- gettextf("SELECT %s, COUNT(*) FROM %s %s GROUP BY 1 ORDER BY 1", caseText, obj, wc) 54 | sz <- try(tdQuery(query)) 55 | csums <- paste(gettextf("SUM(C%d) AS C%d", 1:centers, 1:centers), collapse = ",") 56 | subq <- gettextf("SELECT %s,%s FROM %s %s GROUP BY 1", caseText, paste(.td.genclusterss(initClusters), collapse = ","), 57 | obj, wc) 58 | query <- gettextf("SELECT %s FROM (%s) A", csums, subq) 59 | withinss <- try(tdQuery(query)) 60 | oList <- vector("list", 4) 61 | names(oList) <- c("cluster", "centers", "withinss", "size") 62 | attr(oList, "class") <- "kmeans" 63 | oList$centers <- as.matrix(initClusters) 64 | oList$size <- sz[[2]] 65 | if (is.data.frame(withinss)) 66 | oList$withinss <- as.vector(withinss[1, ]) 67 | 68 | return(oList) 69 | } 70 | 71 | .td.genclusterid <- function(centroids, AS = "clusterID") { 72 | ccnt <- nrow(centroids) 73 | nms <- names(centroids) 74 | cText <- c() 75 | caseText <- c("CASE") 76 | for (i in 1:ccnt) cText[i] <- paste("sqrt(", gettextf("(%f-\"%s\")**2", centroids[i, ], nms), ")", sep = "", collapse = "+") 77 | 78 | if (ccnt > 1) { 79 | for (i in 1:(ccnt - 1)) { 80 | caseText <- c(caseText, " WHEN ") 81 | for (j in (i + 1):ccnt) { 82 | if (j != (i + 1)) 83 | caseText <- c(caseText, " AND ") 84 | caseText <- c(caseText, gettextf("(%s <= %s)", cText[i], cText[j])) 85 | } 86 | caseText <- c(caseText, " THEN ", i, " ") 87 | } 88 | } else caseText <- c(caseText, gettextf(" WHEN (1=1) THEN 1 ", cText[1])) 89 | caseText <- c(caseText, " ELSE ", ccnt, " END AS ", AS) 90 | caseText <- paste(caseText, collapse = "") 91 | 92 | return(caseText) 93 | } 94 | 95 | .td.genclusterss <- function(centroids) { 96 | ccnt <- nrow(centroids) 97 | nms <- names(centroids) 98 | cText <- c() 99 | for (i in 1:ccnt) { 100 | cText[i] <- paste("(", gettextf("(%f-\"%s\")**2", centroids[i, ], nms), ")", sep = "", collapse = "+") 101 | cText[i] <- paste("SUM(CASE WHEN clusterID = ", i, " THEN ", cText[i], " ELSE 0 END) AS C", i, sep = "") 102 | } 103 | return(cText) 104 | } 105 | -------------------------------------------------------------------------------- /R/td.ks.R: -------------------------------------------------------------------------------- 1 | td.ks <- function(tdf, col, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col) || !nchar(col)) 5 | stop("'col' not specified.") 6 | if (thresh <= 0 || thresh >= 1) 7 | stop("'thresh' value must be greater than 0 and less than 1.") 8 | query <- .td.genks(tdf, col, thresh) 9 | df <- tdQuery(query) 10 | return(df) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /R/td.lilliefors.R: -------------------------------------------------------------------------------- 1 | td.lilliefors <- function(tdf, col, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col) || !nchar(col)) 5 | stop("'col' not specified.") 6 | if (thresh <= 0 || thresh >= 1) 7 | stop("'thresh' value must be greater than 0 and less than 1.") 8 | query <- .td.genlilliefors(tdf, col, thresh) 9 | df <- tdQuery(query) 10 | return(df) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /R/td.merge.R: -------------------------------------------------------------------------------- 1 | td.merge <- function(tdf1, tdf2, oTable = "newMergeTable", oDatabase = "", mergeType = "union") { 2 | oObj <- .td.object(oTable, oDatabase) 3 | 4 | mtypes <- c("union", "minus", "intersect") 5 | mlist <- paste(mtypes, collapse = ",") 6 | if (!mergeType %in% mtypes) 7 | stop(gettextf("Unknown 'mergeType'. Must be one of %s", mlist)) 8 | mergeText <- .td.genmerge(tdf1, tdf2, mergeType) 9 | if (.td.objectExists(oObj)) 10 | stop(gettextf("Table %s already exists.", oObj)) 11 | query <- gettextf("CREATE TABLE %s AS (%s) WITH DATA", oObj, mergeText) 12 | df <- try(tdQueryUpdate(query)) 13 | if (length(df) == 1L && df == "No Data") 14 | return(td.data.frame(oTable, oDatabase)) else stop(gettextf("Error: %s", paste(df, collapse = ""))) 15 | } 16 | 17 | -------------------------------------------------------------------------------- /R/td.mode.R: -------------------------------------------------------------------------------- 1 | td.mode <- function(tdf, col) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (!length(names(tdf))) 5 | stop("td.data.frame contains no columns") 6 | if (missing(col) && length(tdf) == 1L) 7 | col <- names(tdf)[1] 8 | query <- .td.genmode(tdf, col) 9 | df <- try(tdQuery(query)) 10 | if (is.null(class(df))) 11 | stop("Error retrieving mode values from table.") 12 | return(df) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/td.mwnkw.R: -------------------------------------------------------------------------------- 1 | td.mwnkw <- function(tdf, col1, col2, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col1) || !nchar(col1)) 5 | stop("'col1' not specified.") 6 | if (missing(col2) || !length(col2)) 7 | stop("'col2' not specified.") 8 | if (thresh <= 0 || thresh >= 1) 9 | stop("'thresh' value must be greater than 0 and less than 1.") 10 | query <- .td.genmwnkw(tdf, col1, col2, thresh) 11 | df <- tdQuery(query) 12 | return(df) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/td.nullreplace.R: -------------------------------------------------------------------------------- 1 | td.nullreplace <- function(tdf, col, oTable, oDatabase = "", rType = "literal", rVal = 0) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 5 | wc <- "" 6 | if (!is.null(attr(tdf, "whereClause"))) 7 | wc <- paste(" WHERE ", attr(tdf, "whereClause")) 8 | oObj <- .td.object(oTable, oDatabase) 9 | nm <- names(tdf) 10 | if (!col %in% nm) 11 | stop("'col' to transform is not a column in the td data frame.") 12 | nm <- nm[-(grep(col, nm))] 13 | nms <- paste(rep(gettextf("\"%s\"", nm)), collapse = ",") 14 | nrepText <- .td.gennrep(col, as = col, rType, rVal) 15 | nms <- paste(nms, ",", nrepText, collapse = ",") 16 | if (rType == "literal") 17 | query <- gettextf("CREATE TABLE %s AS (SELECT %s FROM %s %s) WITH DATA", oObj, nms, obj, wc) else if (rType == "mean") 18 | query <- gettextf("CREATE TABLE %s AS (SELECT %s FROM %s, (%s) A %s) WITH DATA", oObj, nms, obj, gettextf("SELECT %s FROM %s %s", 19 | paste(.td.genstats(col, c("mean")), collapse = ","), obj, wc), wc) else if (rType == "mode") 20 | query <- gettextf("CREATE TABLE %s AS (SELECT %s FROM %s, (%s) A %s) WITH DATA", oObj, nms, obj, .td.genmode(tdf, 21 | col), wc) else if (rType == "median") 22 | query <- gettextf("CREATE TABLE %s AS (SELECT %s FROM %s, (%s) A %s) WITH DATA", oObj, nms, obj, .td.genmedian(tdf, 23 | col), wc) else query <- gettextf("CREATE TABLE %s AS (SELECT %s FROM %s %s) WITH DATA", oObj, nms, obj, wc) 24 | if (.td.objectExists(oObj)) 25 | stop(gettextf("Table %s already exists.", oObj)) 26 | df <- try(tdQueryUpdate(query)) 27 | if (length(df) == 1L && df == "No Data") 28 | return(td.data.frame(oTable, oDatabase)) else stop(gettextf("Error: %s", paste(df, collapse = ""))) 29 | stop(gettextf("Error: %s", paste(df, collapse = ""))) 30 | } 31 | 32 | -------------------------------------------------------------------------------- /R/td.overlap.R: -------------------------------------------------------------------------------- 1 | td.overlap <- function(tdf1, tdf2, fields1, fields2) { 2 | if (missing(fields1)) 3 | fields1 <- .td.getPrimaryIndicies(tdf1) 4 | if (missing(fields2)) 5 | fields2 <- .td.getPrimaryIndicies(tdf2) 6 | query <- .td.genoverlap(tdf1, tdf2, fields1, fields2) 7 | df <- try(tdQuery(query)) 8 | if (class(df) == "data.frame") 9 | return(df) else stop(gettextf("Error: %s", paste(df[1], collapse = ""))) 10 | } 11 | 12 | -------------------------------------------------------------------------------- /R/td.quantiles.R: -------------------------------------------------------------------------------- 1 | td.quantiles <- function(tdf, col, qType = c("ter", "quar", "dec")) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (!length(names(tdf))) 5 | stop("td.data.frame contains no columns") 6 | if (!all(qType %in% c("ter", "quar", "dec"))) 7 | stop("'qType' is not a valid type.") 8 | if (missing(col)) 9 | col <- .td.gencolumnexpr(tdf[names(tdf)[1]]) else col <- .td.gencolumnexpr(tdf[col]) 10 | 11 | query <- .td.genquantiles(tdf, col, qType) 12 | df <- try(tdQuery(query)) 13 | if (is.null(class(df))) 14 | stop("Error retrieving quantile values from table.") 15 | return(df) 16 | } 17 | 18 | -------------------------------------------------------------------------------- /R/td.rank.R: -------------------------------------------------------------------------------- 1 | td.rank <- function(tdf, col) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (!length(names(tdf))) 5 | stop("td.data.frame contains no columns") 6 | if (missing(col) && length(tdf) == 1L) 7 | col <- names(tdf)[1] 8 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 9 | query <- .td.genrank(tdf, col) 10 | df <- try(tdQuery(query)) 11 | if (is.null(class(df))) 12 | stop("Error retrieving rank values from table.") 13 | return(df) 14 | } 15 | 16 | -------------------------------------------------------------------------------- /R/td.recode.R: -------------------------------------------------------------------------------- 1 | td.recode <- function(tdf, col, oTable, oDatabase = "", codes, other = "same") { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (length(codes)%%2 != 0) 5 | stop("Length of 'codes' is not an even number") 6 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 7 | wc <- "" 8 | if (!is.null(attr(tdf, "whereClause"))) 9 | wc <- paste(" WHERE ", attr(tdf, "whereClause")) 10 | oObj <- .td.object(oTable, oDatabase) 11 | nm <- names(tdf) 12 | if (!col %in% nm) 13 | stop("'col' to transform is not a column in the td data frame.") 14 | nm <- nm[-(grep(col, nm))] 15 | nms <- paste(rep(gettextf("\"%s\"", nm)), collapse = ",") 16 | recodeText <- .td.genrecode(col, codes, as = col, other) 17 | nms <- paste(nms, ",", recodeText, collapse = ",") 18 | query <- gettextf("CREATE TABLE %s AS (SELECT %s FROM %s %s) WITH DATA", oObj, nms, obj, wc) 19 | if (.td.objectExists(oObj)) 20 | stop(gettextf("Table %s already exists.", oObj)) 21 | df <- try(tdQueryUpdate(query)) 22 | if (length(df) == 1L && df == "No Data") 23 | return(td.data.frame(oTable, oDatabase)) 24 | stop(gettextf("Error: %s", paste(df, collapse = ""))) 25 | } 26 | 27 | -------------------------------------------------------------------------------- /R/td.rescale.R: -------------------------------------------------------------------------------- 1 | td.rescale <- function(tdf, col, oTable, oDatabase = "", lower = 0, upper = 1) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 5 | wc <- "" 6 | if (!is.null(attr(tdf, "whereClause"))) 7 | wc <- paste(" WHERE ", attr(tdf, "whereClause")) 8 | oObj <- .td.object(oTable, oDatabase) 9 | nm <- names(tdf) 10 | if (!col %in% nm) 11 | stop("'col' to transform is not a column in the td data frame.") 12 | nm <- nm[-(grep(col, nm))] 13 | nms <- paste(rep(gettextf("\"%s\"", nm)), collapse = ",") 14 | rescaleText <- .td.genrescale(col, as = col, lower, upper) 15 | nms <- paste(nms, ",", rescaleText, collapse = ",") 16 | query <- gettextf("CREATE TABLE %s AS (SELECT %s FROM %s, (%s) A %s) WITH DATA", oObj, nms, obj, gettextf("SELECT %s FROM %s %s", 17 | paste(.td.genstats(col, c("min", "max")), collapse = ","), obj, wc), wc) 18 | if (.td.objectExists(oObj)) 19 | stop(gettextf("Table %s already exists.", oObj)) 20 | df <- try(tdQueryUpdate(query)) 21 | if (length(df) == 1L && df == "No Data") 22 | return(td.data.frame(oTable, oDatabase)) else stop(gettextf("Error: %s", paste(df, collapse = ""))) 23 | stop(gettextf("Error: %s", paste(df, collapse = ""))) 24 | } 25 | 26 | -------------------------------------------------------------------------------- /R/td.sample.R: -------------------------------------------------------------------------------- 1 | td.sample <- function(tdf, sizes = missing, oTable = "", oDatabase = "") { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 5 | exprs <- attr(tdf, "expressions") 6 | 7 | if (missing(sizes)) { 8 | query <- .td.tdf2sql(tdf) 9 | } else { 10 | query <- .td.tdf2sql(tdf, sizes) 11 | } 12 | 13 | if (nchar(oTable)) { 14 | oObj <- .td.object(oTable, oDatabase) 15 | if (.td.objectExists(oObj)) 16 | stop(gettextf("Table %s already exists.", oObj)) 17 | query <- gettextf("CREATE TABLE %s AS (%s) WITH DATA", oObj, query) 18 | df <- try(tdQueryUpdate(query)) 19 | } else { 20 | df <- try(tdQuery(query)) 21 | } 22 | 23 | if (is.data.frame(df)) 24 | return(df) 25 | if (length(df) == 1L && df == "No Data") 26 | return(td.data.frame(oTable, oDatabase)) 27 | if (length(df) == 2L) 28 | stop(df[1]) 29 | stop("Unknown error in td.sample") 30 | } 31 | 32 | -------------------------------------------------------------------------------- /R/td.shapiro.wilk.R: -------------------------------------------------------------------------------- 1 | td.shapiro.wilk <- function(tdf, col, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col) || !nchar(col)) 5 | stop("'col' not specified.") 6 | if (thresh <= 0 || thresh >= 1) 7 | stop("'thresh' value must be greater than 0 and less than 1.") 8 | query <- .td.genshapirowilk(tdf, col, thresh) 9 | df <- tdQuery(query) 10 | return(df) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /R/td.sigmoid.R: -------------------------------------------------------------------------------- 1 | td.sigmoid <- function(tdf, col, oTable, oDatabase = "", sigmoidType = "logit") { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 5 | wc <- "" 6 | if (!is.null(attr(tdf, "whereClause"))) 7 | wc <- paste(" WHERE ", attr(tdf, "whereClause")) 8 | oObj <- .td.object(oTable, oDatabase) 9 | nm <- names(tdf) 10 | if (!col %in% nm) 11 | stop("'col' to transform is not a column in the td data frame.") 12 | nm <- nm[-(grep(col, nm))] 13 | nms <- paste(rep(gettextf("\"%s\"", nm)), collapse = ",") 14 | sigmoidText <- .td.gensigmoid(col, sigmoidType, as = col) 15 | nms <- paste(nms, ",", sigmoidText, collapse = ",") 16 | query <- gettextf("CREATE TABLE %s AS (SELECT %s FROM %s %s) WITH DATA", oObj, nms, obj, wc) 17 | if (.td.objectExists(oObj)) 18 | stop(gettextf("Table %s already exists.", oObj)) 19 | df <- try(tdQueryUpdate(query)) 20 | if (length(df) == 1L && df == "No Data") 21 | return(td.data.frame(oTable, oDatabase)) else stop(gettextf("Error: %s", paste(df, collapse = ""))) 22 | stop(gettextf("Error: %s", paste(df, collapse = ""))) 23 | } 24 | 25 | -------------------------------------------------------------------------------- /R/td.smirnov.R: -------------------------------------------------------------------------------- 1 | td.smirnov <- function(tdf, col1, col2, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col1) || !nchar(col1)) 5 | stop("'col1' not specified.") 6 | if (missing(col2) || !length(col2)) 7 | stop("'col2' not specified.") 8 | if (thresh <= 0 || thresh >= 1) 9 | stop("'thresh' value must be greater than 0 and less than 1.") 10 | query <- .td.gensmirnov(tdf, col1, col2, thresh) 11 | df <- tdQuery(query) 12 | return(df) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/td.solve.R: -------------------------------------------------------------------------------- 1 | td.solve <- function(tdf, rhscols) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (!length(names(tdf))) 5 | stop("td.data.frame contains no columns") 6 | lhs <- which(!names(tdf) %in% rhscols) 7 | rhs <- which(names(tdf) %in% rhscols) 8 | df <- td.cor(tdf) 9 | m1 <- df[lhs, lhs] 10 | m2 <- df[lhs, rhs] 11 | return(solve(m1, m2)) 12 | } 13 | 14 | -------------------------------------------------------------------------------- /R/td.stats.R: -------------------------------------------------------------------------------- 1 | td.stats <- function(tdf, col, which = "all", type = "population", group.by = NULL) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (!missing(group.by) && !is.td.data.frame(group.by)) 5 | stop("'group.by' is not a td data frame") 6 | if (!length(names(tdf))) 7 | stop("td.data.frame contains no columns") 8 | 9 | wc <- "" 10 | if (!is.null(attr(tdf, "whereClause"))) 11 | wc <- paste("WHERE", attr(tdf, "whereClause")) 12 | 13 | if (missing(col)) { 14 | nm <- names(tdf)[1] 15 | col <- .td.gencolumnexpr(tdf[names(tdf)[1]]) 16 | } else nm <- col 17 | 18 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 19 | stats <- .td.genstats(col, which, type) 20 | if (is.null(group.by)) 21 | query <- gettextf("SELECT '%s' as col,%s FROM %s %s", nm, paste(stats, collapse = ","), obj, wc) else { 22 | gb <- paste("\"", names(group.by), "\"", sep = "", collapse = ",") 23 | query <- gettextf("SELECT %s,'%s' as col,%s FROM %s %s GROUP BY %s ORDER BY %s", gb, nm, paste(stats, collapse = ","), 24 | obj, wc, gb, gb) 25 | } 26 | df <- tdQuery(query) 27 | if (is.data.frame(df)) 28 | return(df) 29 | return(df[1]) 30 | } 31 | 32 | -------------------------------------------------------------------------------- /R/td.t.paired.R: -------------------------------------------------------------------------------- 1 | td.t.paired <- function(tdf, col1, col2, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col1) || !nchar(col1)) 5 | stop("'col1' not specified.") 6 | if (missing(col2) || !length(col2)) 7 | stop("'col2' not specified.") 8 | if (thresh <= 0 || thresh >= 1) 9 | stop("'thresh' value must be greater than 0 and less than 1.") 10 | query <- .td.gentpaired(tdf, col1, col2, thresh) 11 | df <- tdQuery(query) 12 | return(df) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/td.t.unpaired.R: -------------------------------------------------------------------------------- 1 | td.t.unpaired <- function(tdf, col1, col2, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col1) || !nchar(col1)) 5 | stop("'col1' not specified.") 6 | if (missing(col2) || !length(col2)) 7 | stop("'col2' not specified.") 8 | if (thresh <= 0 || thresh >= 1) 9 | stop("'thresh' value must be greater than 0 and less than 1.") 10 | query <- .td.gentunpaired(tdf, col1, col2, thresh) 11 | df <- tdQuery(query) 12 | return(df) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/td.t.unpairedi.R: -------------------------------------------------------------------------------- 1 | td.t.unpairedi <- function(tdf, col1, col2, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col1) || !nchar(col1)) 5 | stop("'col1' not specified.") 6 | if (missing(col2) || !length(col2)) 7 | stop("'col2' not specified.") 8 | if (thresh <= 0 || thresh >= 1) 9 | stop("'thresh' value must be greater than 0 and less than 1.") 10 | query <- .td.gentunpairedi(tdf, col1, col2, thresh) 11 | df <- tdQuery(query) 12 | return(df) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/td.tapply.R: -------------------------------------------------------------------------------- 1 | td.tapply <- function(X, INDEX, FUN = NULL, asdf = FALSE, ...) { 2 | if (!inherits(X, "td.data.frame")) 3 | stop("'X' is not a td data frame") 4 | if (!inherits(INDEX, "td.data.frame")) 5 | stop("'INDEX' is not a td data frame") 6 | 7 | if (!is.null(FUN)) { 8 | fnc <- character(0) 9 | 10 | if (identical(sum, FUN) || (is.character(FUN) && FUN == "sum")) 11 | fnc <- "sum" 12 | if (identical(min, FUN) || (is.character(FUN) && FUN == "min")) 13 | fnc <- "min" 14 | if (identical(max, FUN) || (is.character(FUN) && FUN == "max")) 15 | fnc <- "max" 16 | if (identical(mean, FUN) || (is.character(FUN) && FUN == "mean")) 17 | fnc <- "mean" 18 | 19 | if (identical(td.stats, FUN) || (is.character(FUN) && FUN == "td.stats")) { 20 | if (asdf) 21 | return(td.stats(X, group.by = INDEX)) 22 | 23 | return(.td.dataframe2array(td.stats(X, group.by = INDEX), INDEX)) 24 | } 25 | 26 | if (identical(td.values, FUN) || (is.character(FUN) && FUN == "td.values")) { 27 | if (asdf) 28 | return(td.values(X, group.by = INDEX)) 29 | 30 | return(.td.dataframe2array(td.values(X, group.by = INDEX), INDEX)) 31 | } 32 | 33 | if (length(fnc)) { 34 | fmt <- "SELECT %s,%s FROM %s GROUP BY %s ORDER BY %s" 35 | if (length(INDEX) > 2) 36 | srt <- paste("\"", names(INDEX)[2:length(INDEX)], "\"", sep = "", collapse = ",") else srt <- paste("\"", names(INDEX), "\"", sep = "", collapse = ",") 37 | nms <- paste("\"", names(INDEX), "\"", sep = "", collapse = ",") 38 | obj <- .td.object(attr(X, "tableName"), attr(X, "database")) 39 | query <- gettextf(fmt, nms, .td.genstats(names(X)[1], fnc), obj, nms, srt) 40 | res <- tdQuery(query) 41 | if (asdf) 42 | return(res) 43 | return(.td.dataframe2array(res, INDEX)) 44 | # vals <- list() dms <- integer(0) for(i in 1:(length(res)-1)) { vals[[i]] <- as.vector(sort(unique(res[[i]]))) dms[i] 45 | # <- length(vals[[i]]) } names(vals) <- names(INDEX) arr <- array(dim = dms, dimnames=vals) for(i in 1:nrow(res)) { mat 46 | # <- matrix(as.character(res[i,1:length(dms)]), nrow=1) arr[mat] <- res[i,length(res)] } 47 | 48 | # return(arr) 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /R/td.values.R: -------------------------------------------------------------------------------- 1 | td.values <- function(tdf, col, group.by = NULL) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (!length(names(tdf))) 5 | stop("td.data.frame contains no columns") 6 | if (!missing(group.by) && !is.td.data.frame(group.by)) 7 | stop("'group.by' is not a td data frame") 8 | 9 | wc <- "" 10 | if (!is.null(attr(tdf, "whereClause"))) 11 | wc <- paste("WHERE", attr(tdf, "whereClause")) 12 | 13 | if (missing(col)) { 14 | nm <- names(tdf)[1] 15 | col <- .td.gencolumnexpr(tdf[names(tdf)[1]]) 16 | } else { 17 | nm <- col 18 | col <- .td.gencolumnexpr(tdf[col]) 19 | } 20 | 21 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 22 | values <- .td.genvalues(col) 23 | 24 | if (!is.null(attr(tdf[nm], "expressions"))) 25 | fnc <- .td.objectIsNumeric2 else fnc <- .td.objectIsNumeric 26 | 27 | if (fnc(attr(tdf, "database"), attr(tdf, "tableName"), col)) 28 | vals <- paste(values[1:5], collapse = ",") else vals <- paste(values[c(1, 5, 6)], collapse = ",") 29 | 30 | if (length(group.by)) { 31 | gb <- paste("\"", names(group.by), "\"", sep = "", collapse = ",") 32 | query <- gettextf("SELECT %s,'%s' as col,%s FROM %s %s GROUP BY %s ORDER BY %s", gb, nm, vals, obj, wc, gb, gb) 33 | } else query <- gettextf("SELECT '%s' as col,%s FROM %s %s", nm, vals, obj, wc) 34 | return(tdQuery(query)) 35 | } 36 | 37 | -------------------------------------------------------------------------------- /R/td.wilcoxon.R: -------------------------------------------------------------------------------- 1 | td.wilcoxon <- function(tdf, col1, col2, thresh = 0.05) { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | if (missing(col1) || !nchar(col1)) 5 | stop("'col1' not specified.") 6 | if (missing(col2) || !length(col2)) 7 | stop("'col2' not specified.") 8 | if (thresh <= 0 || thresh >= 1) 9 | stop("'thresh' value must be greater than 0 and less than 1.") 10 | query <- .td.genwilcoxon(tdf, col1, col2, thresh) 11 | df <- tdQuery(query) 12 | return(df) 13 | } 14 | 15 | -------------------------------------------------------------------------------- /R/td.zscore.R: -------------------------------------------------------------------------------- 1 | td.zscore <- function(tdf, col, oTable, oDatabase = "") { 2 | if (!is.td.data.frame(tdf)) 3 | stop("'tdf' is not a td data frame") 4 | obj <- .td.object(attr(tdf, "tableName"), attr(tdf, "database")) 5 | oObj <- .td.object(oTable, oDatabase) 6 | wc <- "" 7 | if (!is.null(attr(tdf, "whereClause"))) 8 | wc <- paste("WHERE", attr(tdf, "whereClause")) 9 | nm <- names(tdf) 10 | if (!col %in% nm) 11 | stop("'col' to transform is not a column in the td data frame.") 12 | nm <- nm[-(grep(col, nm))] 13 | nms <- paste(rep(gettextf("\"%s\"", nm)), collapse = ",") 14 | zscoreText <- .td.genzscore(col, as = col) 15 | nms <- paste(nms, ",", zscoreText, collapse = ",") 16 | query <- gettextf("CREATE TABLE %s AS (SELECT %s FROM %s, (%s) A %s) WITH DATA", oObj, nms, obj, gettextf("SELECT %s FROM %s %s", 17 | paste(.td.genstats(col, c("mean", "std")), collapse = ","), obj, wc), wc) 18 | if (.td.objectExists(oObj)) 19 | stop(gettextf("Table %s already exists.", oObj)) 20 | df <- try(tdQueryUpdate(query)) 21 | if (length(df) == 1L && df == "No Data") 22 | return(td.data.frame(oTable, oDatabase)) else stop(gettextf("Error: %s", paste(df, collapse = ""))) 23 | stop(gettextf("Error: %s", paste(df, collapse = ""))) 24 | } 25 | 26 | -------------------------------------------------------------------------------- /R/tdClose.R: -------------------------------------------------------------------------------- 1 | tdClose <- function(x = tdConnection) { 2 | if (class(tdConnection) == "RODBC") 3 | close(x) 4 | if (class(tdConnection) == "JDBCConnection") 5 | dbDisconnect(x) 6 | } 7 | 8 | -------------------------------------------------------------------------------- /R/tdConnect.R: -------------------------------------------------------------------------------- 1 | tdConnect <- function(dsn, uid = "", pwd = "", database = "", dType = "odbc") { 2 | if (dType == "odbc") { 3 | require(RODBC) 4 | st <- paste("DSN=", dsn, sep = "") 5 | if (nchar(uid)) 6 | st <- paste(st, ";UID=", uid, sep = "") 7 | if (nchar(pwd)) 8 | st <- paste(st, ";PWD=", pwd, sep = "") 9 | if (nchar(database)) 10 | st <- paste(st, ";Database=", database, sep = "") 11 | tdConnection <- odbcDriverConnect(st) 12 | assign("tdConnection", tdConnection, envir = .GlobalEnv) 13 | invisible(tdConnection) 14 | } 15 | 16 | if (dType == "jdbc") { 17 | require(RJDBC) 18 | drv <- JDBC("com.teradata.jdbc.TeraDriver") 19 | st <- paste("jdbc:teradata://", dsn, sep = "") 20 | if (nchar(database)) 21 | st <- paste(st, "/database=", database, sep = "") 22 | tdConnection <- dbConnect(drv, st, user = uid, password = pwd) 23 | assign("tdConnection", tdConnection, envir = .GlobalEnv) 24 | invisible(tdConnection) 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /R/tdMetadataDB.R: -------------------------------------------------------------------------------- 1 | tdMetadataDB <- function(database) { 2 | if (!is.null(database) && nchar(database)) { 3 | assign("tdMetadata", database, envir = .GlobalEnv) 4 | invisible(tdMetadata) 5 | } else { 6 | if (exists("tdMetadata", envir = .GlobalEnv)) 7 | remove(tdMetadata, envir = .GlobalEnv) 8 | invisible(NA) 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /R/tdQuery.R: -------------------------------------------------------------------------------- 1 | tdQuery <- function(q, ...) { 2 | if (class(tdConnection) == "RODBC") 3 | return(sqlQuery(tdConnection, q, stringsAsFactors=FALSE, ...)) 4 | if (class(tdConnection) == "JDBCConnection") 5 | return(dbGetQuery(tdConnection, q, ...)) 6 | } 7 | 8 | -------------------------------------------------------------------------------- /R/tdQueryUpdate.R: -------------------------------------------------------------------------------- 1 | tdQueryUpdate <- function(q, ...) { 2 | if (class(tdConnection) == "RODBC") 3 | return(sqlQuery(tdConnection, q, ...)) 4 | if (class(tdConnection) == "JDBCConnection") { 5 | dbSendUpdate(tdConnection, q, ...) 6 | return("No Data") 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /R/tdSave.R: -------------------------------------------------------------------------------- 1 | tdSave <- function(x, tablename = "") { 2 | if (inherits(x, "td.data.frame")) 3 | return(x) 4 | if (inherits(x, "data.frame")) { 5 | if (nchar(tablename) > 0) 6 | tbl <- tablename else tbl <- deparse(substitute(x)) 7 | if (class(tdConnection) == "RODBC") { 8 | sqlSave(tdConnection, x, tablename = tbl) 9 | return(td.data.frame(tbl)) 10 | } 11 | 12 | if (class(tdConnection) == "JDBCConnection") { 13 | dbWriteTable(tdConnection, name = tbl, value = x) 14 | return(td.data.frame(tbl)) 15 | } 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /R/z[.td.data.frame.R: -------------------------------------------------------------------------------- 1 | `[.td.data.frame` <- function(x, i, j) { 2 | Nargs <- nargs() 3 | if (missing(i) && (missing(j) || Nargs == 2L)) 4 | return(x) 5 | if (Nargs == 2L || missing(i)) { 6 | cols <- if (missing(i)) 7 | j else i 8 | if (!is.numeric(cols) && !is.character(cols) && !is.logical(cols)) 9 | stop(gettextf("Invalid subscript type '%s'", typeof(cols))) 10 | if (is.character(cols)) 11 | cols <- match(make.unique(cols), names(x)) 12 | if (is.logical(cols)) 13 | cols <- match(names(x)[rep(cols, length.out = length(names(x)))], names(x)) 14 | if (any(is.na(cols)) || !all(cols <= length(x))) 15 | stop("Undefined columns selected") 16 | if (any(cols < 0) && any(cols > 0)) 17 | stop("only 0's may be mixed with negative subscripts") 18 | if (any(cols < 0)) 19 | cols <- (1:length(x))[cols] 20 | a <- attributes(x) 21 | a$names <- NULL 22 | y <- NextMethod("[") 23 | if (any(duplicated(names(y)))) { 24 | y <- y[which(!duplicated(names(y)))] 25 | cols <- unique(cols) 26 | } 27 | a$names <- names(y) 28 | attributes(y) <- a 29 | # y <- x rc <- length(x):1 rc <- (length(x):(length(unique(cols))+1)) for(col in rc) { if(!(col %in% cols)) y[col] <- 30 | # NULL } names(y) <- names(x)[cols] 31 | attr(y, "expressions") <- NULL 32 | # exprs <- attr(x, 'expressions')[which(names(y) %in% names(attr(x,'expressions')))] 33 | exprs <- attr(x, "expressions")[as.character(cols[which(cols %in% names(attr(x, "expressions")))])] 34 | if (!is.null(exprs) && !any(is.na(exprs)) && length(exprs) > 0L) { 35 | names(exprs) <- which(cols %in% names(exprs)) 36 | attr(y, "expressions") <- c(exprs) 37 | } 38 | return(y) 39 | } 40 | 41 | if (missing(j)) { 42 | if (is.character(i)) 43 | stop("Undefined columns selected") 44 | if (is.numeric(i)) { 45 | warning("td data frame unchanged. Use td.sample if you wish to reduce row size for tables.") 46 | return(x) 47 | } 48 | stop(gettextf("Invalid subscript type '%s'", typeof(i))) 49 | } 50 | 51 | warning("td data frame unchanged. Use td.sample if you wish to reduce row size for tables.") 52 | return(x) 53 | } 54 | 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | teradataR 2 | ========= 3 | 4 | R package to perform in-database analytics using Teradata database. 5 | 6 | Compatible with both R version 2 and 3. 7 | 8 | Prebuilt package could be found [here](https://github.com/Teradata/teradataR/raw/master/build/teradataR_1.1.0.tar.gz). 9 | 10 | ## Dependencies 11 | 12 | + RJDBC 13 | + rJava 14 | + RODBC 15 | 16 | ## Installation 17 | 18 | To install the package, issue the following command from R REPL: 19 | 20 | install.packages("C:\\Documents and Settings\\User\\My Documents\\Downloads\\teradataR_1.1.0.tar.gz", repos=NULL,type="source"); 21 | 22 | Where first argument is the path to the package file. 23 | 24 | -------------------------------------------------------------------------------- /build/teradataR_1.1.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teradata/teradataR/453518bf036d9edeee24779a62d14a0033adc6f6/build/teradataR_1.1.0.tar.gz -------------------------------------------------------------------------------- /inst/doc/teradataR.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teradata/teradataR/453518bf036d9edeee24779a62d14a0033adc6f6/inst/doc/teradataR.pdf -------------------------------------------------------------------------------- /man/INITCAP.Rd: -------------------------------------------------------------------------------- 1 | \name{INITCAP} 2 | \alias{INITCAP} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{ 5 | Wrapper Function INITCAP 6 | } 7 | \description{ 8 | Makes a wrapper around the fastpath function INITCAP 9 | } 10 | \usage{ 11 | INITCAP(x) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{x}{ 16 | a teradata dataframe that contains columns of characters that will be capitalized 17 | } 18 | } 19 | \details{ 20 | %% ~~ If necessary, more details than the description above ~~ 21 | } 22 | \value{ 23 | A teradata data frame of the columns that have their first letters capitalized 24 | } 25 | \references{ 26 | %% ~put references to the literature/web site here ~ 27 | } 28 | \author{ 29 | Todd Brye, Erin Cole 30 | } 31 | \note{ 32 | %% ~~further notes~~ 33 | } 34 | 35 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 36 | 37 | \seealso{ 38 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 39 | } 40 | \examples{ 41 | tdf["col2"] <- INITCAP(tdf["col1"]) 42 | } 43 | % Add one or more standard keywords, see file 'KEYWORDS' in the 44 | % R documentation directory. 45 | \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") 46 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 47 | -------------------------------------------------------------------------------- /man/LPAD.Rd: -------------------------------------------------------------------------------- 1 | \name{LPAD} 2 | \alias{LPAD} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{ 5 | Wrapper Function LPAD 6 | } 7 | \description{ 8 | Makes a wrapper around the fastpath function LPAD 9 | } 10 | \usage{ 11 | LPAD(x, ilength, fill_string = " ") 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{x}{ 16 | a teradata dataframe that contains column(s) of characters that will be padded 17 | } 18 | \item{ilength}{ 19 | the amount of padding to append to the beginning of the character 20 | } 21 | \item{fill_string}{ 22 | the character used to pad the the column(s) of characters that are passed into the function. Default character is the empty character 23 | } 24 | } 25 | \details{ 26 | %% ~~ If necessary, more details than the description above ~~ 27 | } 28 | \value{ 29 | A teradata data frame of the columns that have been padded at the beginning 30 | } 31 | \references{ 32 | %% ~put references to the literature/web site here ~ 33 | } 34 | \author{ 35 | Todd Brye, Erin Cole 36 | } 37 | \note{ 38 | %% ~~further notes~~ 39 | } 40 | 41 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 42 | 43 | \seealso{ 44 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 45 | } 46 | \examples{ 47 | tdf["col2"] <- LPAD(tdf["col1", 15, " "]) 48 | } 49 | % Add one or more standard keywords, see file 'KEYWORDS' in the 50 | % R documentation directory. 51 | \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") 52 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 53 | -------------------------------------------------------------------------------- /man/LTRIM.Rd: -------------------------------------------------------------------------------- 1 | \name{LTRIM} 2 | \alias{LTRIM} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{ 5 | Wrapper Function LTRIM 6 | } 7 | \description{ 8 | Makes a wrapper around the fastpath function LTRIM 9 | } 10 | \usage{ 11 | LTRIM(x) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{x}{ 16 | a teradata dataframe that contains column(s) of characters whose padding to their left will be trimmed 17 | } 18 | } 19 | \details{ 20 | %% ~~ If necessary, more details than the description above ~~ 21 | } 22 | \value{ 23 | A teradata data frame of the columns that will be trimmed at the beginning of each character 24 | %% ... 25 | } 26 | \references{ 27 | %% ~put references to the literature/web site here ~ 28 | } 29 | \author{ 30 | Todd Brye, Erin Cole 31 | } 32 | \note{ 33 | %% ~~further notes~~ 34 | } 35 | 36 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 37 | 38 | \seealso{ 39 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 40 | } 41 | \examples{ 42 | tdf["col2"] <- LTRIM(tdf["col1"]) 43 | } 44 | % Add one or more standard keywords, see file 'KEYWORDS' in the 45 | % R documentation directory. 46 | \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") 47 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 48 | -------------------------------------------------------------------------------- /man/RPAD.Rd: -------------------------------------------------------------------------------- 1 | \name{RPAD} 2 | \alias{RPAD} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{ 5 | Wrapper Function RPAD 6 | } 7 | \description{ 8 | Makes a wrapper around the fastpath function RPAD 9 | } 10 | \usage{ 11 | RPAD(x, ilength, fill_string = " ") 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{x}{ 16 | a teradata dataframe that contains column(s) of characters that will be padded 17 | } 18 | \item{ilength}{ 19 | the amount of padding to append to the beginning of the character 20 | } 21 | \item{fill_string}{ 22 | the character used to pad the the column(s) of characters that are passed into the function. Default character is the empty character 23 | } 24 | } 25 | \details{ 26 | %% ~~ If necessary, more details than the description above ~~ 27 | } 28 | \value{ 29 | A teradata data frame of the columns that will be padded at the beginning of each character 30 | } 31 | \references{ 32 | %% ~put references to the literature/web site here ~ 33 | } 34 | \author{ 35 | Todd Brye, Erin Cole 36 | } 37 | \note{ 38 | %% ~~further notes~~ 39 | } 40 | 41 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 42 | 43 | \seealso{ 44 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 45 | } 46 | \examples{ 47 | tdf["col2"] <- RPAD(tdf["col1", 15, " "]) 48 | } 49 | % Add one or more standard keywords, see file 'KEYWORDS' in the 50 | % R documentation directory. 51 | \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") 52 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 53 | -------------------------------------------------------------------------------- /man/RTRIM.Rd: -------------------------------------------------------------------------------- 1 | \name{RTRIM} 2 | \alias{RTRIM} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{ 5 | Wrapper Function RTRIM 6 | } 7 | \description{ 8 | Makes a wrapper around the fastpath function RTRIM 9 | } 10 | \usage{ 11 | RTRIM(x) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{x}{ 16 | a teradata dataframe that contains column(s) of characters whose padding to their right will be trimmed 17 | } 18 | } 19 | \details{ 20 | %% ~~ If necessary, more details than the description above ~~ 21 | } 22 | \value{ 23 | A teradata data frame of the columns that will be trimmed at the end of each character 24 | } 25 | \references{ 26 | %% ~put references to the literature/web site here ~ 27 | } 28 | \author{ 29 | Todd Brye, Erin Cole 30 | } 31 | \note{ 32 | %% ~~further notes~~ 33 | } 34 | 35 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 36 | 37 | \seealso{ 38 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 39 | } 40 | \examples{ 41 | tdf["col2"] <- RTRIM(tdf["col1"]) 42 | } 43 | % Add one or more standard keywords, see file 'KEYWORDS' in the 44 | % R documentation directory. 45 | \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") 46 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 47 | -------------------------------------------------------------------------------- /man/as.data.frame.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{as.data.frame.td.data.frame} 2 | \alias{as.data.frame.td.data.frame} 3 | \title{ 4 | Convert td data frame to a data frame 5 | } 6 | \description{ 7 | Coerce a td data frame object into a data frame. This will access the 8 | Teradata object referenced by the td data frame and select rows from 9 | that object and bring it over as a data frame. 10 | } 11 | \usage{ 12 | \method{as.data.frame}{td.data.frame}(x, size = 100) 13 | } 14 | \arguments{ 15 | \item{x}{td data frame.} 16 | \item{size}{max amount of rows to return from database.} 17 | } 18 | \value{ 19 | data frame 20 | } 21 | 22 | \examples{ 23 | 24 | \dontrun{ 25 | tdf <- td.data.frame("customer") 26 | df <- as.data.frame(tdf) 27 | # Brings 'size' rows of data from Teradata to a data frame 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /man/as.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{as.td.data.frame} 2 | \alias{as.td.data.frame} 3 | \title{ 4 | Coerce to a td data frame 5 | } 6 | \description{ 7 | Coerce a data frame into a td data frame 8 | } 9 | \usage{ 10 | as.td.data.frame(x, ...) 11 | } 12 | \arguments{ 13 | \item{x}{ 14 | data frame. 15 | } 16 | \item{\dots}{ 17 | Allow other commands to be sent to plot. 18 | } 19 | } 20 | \details{ 21 | If a data frame is supplied a new table is created on the Teradata system in the 22 | current database. The new table has the same name as the data frame variable in 23 | R. 24 | } 25 | \value{ 26 | as.td.data.frame return a td.data.frame 27 | } 28 | 29 | \examples{ 30 | 31 | \dontrun{as.td.data.frame(iris)} 32 | #Builds a table named iris in Teradata 33 | 34 | } 35 | % Add one or more standard keywords, see file 'KEYWORDS' in the 36 | % R documentation directory. 37 | \keyword{ ~kwd1 } 38 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 39 | -------------------------------------------------------------------------------- /man/dim.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{dim.td.data.frame} 2 | \alias{dim.td.data.frame} 3 | \title{ 4 | Dimensions of a td data frame 5 | } 6 | \description{ 7 | Retrieve the dimension of a td data frame. 8 | } 9 | \usage{ 10 | \method{dim}{td.data.frame}(x) 11 | } 12 | \arguments{ 13 | \item{x}{ 14 | td data frame. 15 | } 16 | } 17 | \details{ 18 | dim has a method which returns the totalRows and the length of the td.data.frame (as the numbers of rows and columns respectively). 19 | } 20 | \value{ 21 | It is NULL or a vector of mode integer. 22 | } 23 | \examples{ 24 | 25 | \dontrun{ 26 | tdf <- td.data.frame("customer") 27 | dim(tdf) 28 | #returns 29 | #[1] 1000 18 30 | } 31 | 32 | } 33 | % Add one or more standard keywords, see file 'KEYWORDS' in the 34 | % R documentation directory. 35 | \keyword{ ~kwd1 } 36 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 37 | -------------------------------------------------------------------------------- /man/hist.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{hist.td.data.frame} 2 | \alias{hist.td.data.frame} 3 | \title{ 4 | Histograms 5 | } 6 | \description{ 7 | Function to describe a td data frame via plots. 8 | } 9 | \usage{ 10 | \method{hist}{td.data.frame}(x, breaks = 10, \dots) 11 | } 12 | \arguments{ 13 | \item{x}{ 14 | td data frame. 15 | } 16 | \item{breaks}{ 17 | number of groups to break each column up into. 18 | } 19 | \item{\dots}{ 20 | forward information to plots. 21 | } 22 | } 23 | \details{ 24 | This function builds a histogram for each numeric column in the td data frame. 25 | A frequency graph is produced for non numeric columns. The max amount of graphs 26 | is limited to 16 so if you have more columns you can run the command on different 27 | ranges to see all the plots. 28 | } 29 | \value{ 30 | Visual graph of the histogram plots. 31 | } 32 | \examples{ 33 | 34 | \dontrun{ 35 | hist(tdf) #tdf is a td data frame 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/is.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{is.td.data.frame} 2 | \alias{is.td.data.frame} 3 | \title{ 4 | Is an Object a Teradata Data Frame 5 | } 6 | \description{ 7 | Check to see if object has a td.data.frame in its class 8 | } 9 | \usage{ 10 | is.td.data.frame(x) 11 | } 12 | \arguments{ 13 | \item{x}{ 14 | any R Object. 15 | } 16 | } 17 | \value{ 18 | is.data.frame returns TRUE if its argument is a data frame (that is, it has "td.data.frame" amongst its classes) and FALSE otherwise. 19 | } 20 | \examples{ 21 | is.td.data.frame(iris) 22 | #FALSE because iris is a data frame 23 | } 24 | -------------------------------------------------------------------------------- /man/max.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{max.td.data.frame} 2 | \alias{max.td.data.frame} 3 | \title{ 4 | Maxima 5 | } 6 | \description{ 7 | Find the maximum value in the td data frame 8 | } 9 | \usage{ 10 | \method{max}{td.data.frame}(tdf, \dots) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{\dots}{ 17 | conform to generic max 18 | } 19 | } 20 | \details{ 21 | Access database and return the maximum value amoung the current columns in the td data frame. 22 | } 23 | \value{ 24 | Returns the maximum value found as a numeric 25 | } 26 | \note{ 27 | The td data frame must consist of only numeric variables 28 | } 29 | 30 | \examples{ 31 | 32 | \dontrun{ 33 | 34 | tdf <- td.data.frame("customer") 35 | max(tdf) 36 | #Returns max value of columns in customer 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /man/mean.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{mean.td.data.frame} 2 | \alias{mean.td.data.frame} 3 | \title{ 4 | Arithmetic Mean 5 | } 6 | \description{ 7 | Function to calculate the arithmetic mean. 8 | } 9 | \usage{ 10 | \method{mean}{td.data.frame}(x, \dots) 11 | } 12 | \arguments{ 13 | \item{x}{ 14 | td data frame. 15 | } 16 | \item{\dots}{ 17 | For generic consistency. 18 | } 19 | } 20 | \details{ 21 | Means for all numeric columns in the td data frame are returned as well as 22 | NA values for the non numeric columns. 23 | } 24 | \value{ 25 | vector of mean values for each column. 26 | } 27 | \examples{ 28 | 29 | \dontrun{ 30 | mean(tdf) #tdf is a td data frame 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /man/median.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{median.td.data.frame} 2 | \alias{median.td.data.frame} 3 | \title{ 4 | Median Value 5 | } 6 | \description{ 7 | Compute median value. 8 | } 9 | \usage{ 10 | \method{median}{td.data.frame}(x) 11 | } 12 | \arguments{ 13 | \item{x}{ 14 | td data frame. 15 | } 16 | } 17 | \details{ 18 | Function runs against Teradata and finds the median value of a particular column. 19 | } 20 | \value{ 21 | returns numeric median value 22 | } 23 | \examples{ 24 | 25 | \dontrun{ 26 | median(tdf["age"]) 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/min.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{min.td.data.frame} 2 | \alias{min.td.data.frame} 3 | \title{ 4 | Minima 5 | } 6 | \description{ 7 | Find the minimum value in the td data frame 8 | } 9 | \usage{ 10 | \method{min}{td.data.frame}(tdf, ...) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{\dots}{ 17 | conform to generic min 18 | } 19 | } 20 | \details{ 21 | Access database and return the minimum value amoung the current columns in the td data frame. 22 | } 23 | \value{ 24 | Returns the minimum value found as a numeric 25 | } 26 | \note{ 27 | The td data frame must consist of only numeric variables 28 | } 29 | \examples{ 30 | 31 | \dontrun{ 32 | 33 | tdf <- td.data.frame("customer") 34 | min(tdf) 35 | #Returns min value of columns in customer 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /man/on.Rd: -------------------------------------------------------------------------------- 1 | \name{on} 2 | \alias{on} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{ 5 | On Function 6 | } 7 | \description{ 8 | Creates A representation of an ON Clause in an ExecR Table Operator query. 9 | } 10 | \usage{ 11 | on(target=NULL, from=NULL, subQuery=NULL, partition=NULL, hash=NULL, order=NULL, local_order=NULL, null_order=NULL, dimension=NULL, as=NULL) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{target}{ 16 | a character that represents a name of a table or a query expression 17 | } 18 | \item{from}{ 19 | a character that represents a name of the origin of a query expression 20 | } 21 | \item{subQuery}{ 22 | a character that represents a nested ON Clause or nested query expression that is part of an ON Clause 23 | } 24 | \item{partition}{ 25 | the parallel option, partition by , or partition by 26 | } 27 | \item{hash}{ 28 | the parallel option, hash by 29 | } 30 | \item{order}{ 31 | the parallel option, order by 32 | } 33 | \item{local_order}{ 34 | the parallel option, local order by 35 | } 36 | \item{null_order}{ 37 | specification for the parallel option local_order 38 | } 39 | \item{dimension}{ 40 | the parallel option, dimension 41 | } 42 | \item{as}{ 43 | creates and alias 44 | } 45 | } 46 | \details{ 47 | %% ~~ If necessary, more details than the description above ~~ 48 | } 49 | \value{ 50 | a string representation of an ON Clause for a table operator 51 | } 52 | \references{ 53 | %% ~put references to the literature/web site here ~ 54 | } 55 | \author{ 56 | Erin Cole 57 | } 58 | \note{ 59 | %% ~~further notes~~ 60 | } 61 | 62 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 63 | 64 | \seealso{ 65 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 66 | } 67 | \examples{ 68 | o <- on(target="select *" from="tab1", partition="any") 69 | } 70 | % Add one or more standard keywords, see file 'KEYWORDS' in the 71 | % R documentation directory. 72 | \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") 73 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 74 | -------------------------------------------------------------------------------- /man/predict.kmeans.Rd: -------------------------------------------------------------------------------- 1 | \name{predict.kmeans} 2 | \alias{predict.kmeans} 3 | \title{ 4 | Kmeans Model Prediction 5 | } 6 | \description{ 7 | predict is a generic function for predictions from the results of various model fitting functions. This function is invoked when predict is used on a class of type 'kmeans'. 8 | } 9 | \usage{ 10 | \method{predict}{kmeans}(object, newdata=NULL, oTable="", oDatabase="", \dots) 11 | } 12 | \arguments{ 13 | \item{object}{ 14 | object of type 'kmeans'. 15 | } 16 | \item{newdata}{ 17 | td data frame or data frame to predict. 18 | } 19 | \item{oTable}{ 20 | Output table name if a td data frame is being predicted. 21 | } 22 | \item{oDatabase}{ 23 | Output database name if a td data frame is being predicted. 24 | } 25 | \item{\dots}{ 26 | Generic parameter list. 27 | } 28 | } 29 | \details{ 30 | When using this function with a td data frame you must at least include the 'oTable' parameter for the table name that will be 31 | written in the Teradata database. An optional 'oDatabase' parameter is included to allow creating the table in other databases 32 | within the Teradata database. The prediction will build a table from the td data frame including all the column names and 33 | adding a new column called 'clusterID' which will have the predictions from applying the 'kmeans' object to your Teradata 34 | table pointed to in your td data frame. This function is also able to score a regular R data frame object. 35 | } 36 | \value{ 37 | A td data frame will be returned if your 'newdata' object is of type td data frame. It will point to your newly created table. 38 | A vector of cluster scores will be returned if you are scoring a regular data frame. 39 | } 40 | \examples{ 41 | 42 | \dontrun{ 43 | tdf <- td.data.frame("customer") 44 | tkm <- td.kmeans(tdf[1:5], centers=3) #use columns 1-5 to cluster on 45 | newTbl <- predict(tkm, tdf, "newcustomerwithcluster") 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /man/print.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{print.td.data.frame} 2 | \alias{print.td.data.frame} 3 | \title{ 4 | Show contents of a td data frame 5 | } 6 | \description{ 7 | Display information about the td data frame such as database, tablename, and 8 | column names. 9 | } 10 | \usage{ 11 | \method{print}{td.data.frame}(x, \dots) 12 | } 13 | \arguments{ 14 | \item{x}{ 15 | td data frame. 16 | } 17 | \item{\dots}{ 18 | Allow other commands to be sent to plot. 19 | } 20 | } 21 | \details{ 22 | Function outputs specific information about the current table pointed at 23 | by this td data frame. Database name, table name, columns and the row count 24 | are all pieces of information that is output. 25 | } 26 | \value{ 27 | A list of the information 28 | } 29 | \examples{ 30 | 31 | \dontrun{ 32 | tdf #a td data frame object 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /man/subset.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{subset.td.data.frame} 2 | \alias{subset.td.data.frame} 3 | \title{ 4 | Subsetting a Teradata Data Frame 5 | } 6 | \description{ 7 | Return subsets of teradata data frames which meet conditions. 8 | } 9 | \usage{ 10 | \method{subset}{td.data.frame}(x, subset, select, drop = FALSE, \dots) 11 | } 12 | \arguments{ 13 | \item{x}{ 14 | td data frame to be subset. 15 | } 16 | \item{subset}{ 17 | logical expression indicating rows to keep. 18 | } 19 | \item{select}{ 20 | expression, indicating columns to select from a teradata data frame. 21 | } 22 | \item{drop}{ 23 | passed on to [ indexing operator. 24 | } 25 | \item{\dots}{ 26 | Allow other commands to be sent to plot. 27 | } 28 | } 29 | \details{ 30 | This is a generic function, with methods supplied for teradata data frames. 31 | 32 | The subset argument works on the rows. Note that subset will be evaluated in the teradata data frame, so columns can be referred to (by name) as variables in the expression (see the examples). 33 | 34 | It works by first replacing column names in the selection expression with the corresponding column numbers in the teradata data frame and then using the resulting integer vector to index the columns. This allows the use of the standard indexing conventions so that for example ranges of columns can be specified easily, or single columns can be dropped (see the examples). 35 | 36 | } 37 | \value{ 38 | An object similar to x but which adds the subset condtion which is used when accessing the real Teradata table. 39 | } 40 | \examples{ 41 | 42 | \dontrun{ 43 | subset(tdf, age >= 65, select = income:married) 44 | subset(tdf, gender == 'F', select = -age) 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /man/sum.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{sum.td.data.frame} 2 | \alias{sum.td.data.frame} 3 | \title{ 4 | Sum of column 5 | } 6 | \description{ 7 | sum returns the sum of all the values present in a column. 8 | } 9 | \usage{ 10 | \method{sum}{td.data.frame}(tdf, \dots) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{\dots}{ 17 | conform to generic sum. 18 | } 19 | } 20 | \details{ 21 | This is an override of the generic sum function. Acces the Teradata system and 22 | return the sum of a particular column or columns. 23 | } 24 | \value{ 25 | A numeric value of the sum. 26 | } 27 | \examples{ 28 | 29 | \dontrun{ 30 | sum(tdf[1:5]) #total sum of 5 columns from td data frame 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /man/summary.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{summary.td.data.frame} 2 | \alias{summary.td.data.frame} 3 | \title{ 4 | Summary of Teradata Data Frame 5 | } 6 | \description{ 7 | Function which returns from a td data frame information just like R summary on 8 | a data frame. 9 | } 10 | \usage{ 11 | \method{summary}{td.data.frame}(tdf, maxsum = 7, digits = max(3, getOption("digits") - 3), ...) 12 | } 13 | \arguments{ 14 | \item{tdf}{ 15 | td data frame. 16 | } 17 | \item{maxsum}{ 18 | max amount of values for non numeric columns. 19 | } 20 | \item{digits}{ 21 | digit precision. 22 | } 23 | \item{\dots}{ 24 | dots to help conform to generic function 25 | } 26 | } 27 | \details{ 28 | Function queries the Teradata table and builds up summary results for all the 29 | columns associated with the td data frame. Similar to summary on a data frame 30 | object. 31 | } 32 | \value{ 33 | summary values for all columns. 34 | } 35 | \examples{ 36 | 37 | \dontrun{ 38 | summary(tdf) #min, max, mean, etc. on all columns of td data frame 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/td.CalcMatrix.Rd: -------------------------------------------------------------------------------- 1 | \name{td.CalcMatrix} 2 | \alias{td.CalcMatrix} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{ 5 | Wrapper function for CalcMatrix 6 | } 7 | \description{ 8 | Creates A wrapper around the CalcMatrix table operator, using R Code. 9 | } 10 | \usage{ 11 | td.CalcMatrix(selectPhrase=string, ons=string, phase=NULL, calctype=NULL, output=NULL, null_handling=NULL, optional_operators=NULL, as=NULL) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{selectPhrase}{ 16 | a character that represents the select clause for a query expression 17 | } 18 | \item{ons}{ 19 | a character or list representation of the needed ON Clauses 20 | } 21 | \item{phase}{ 22 | the character representation of the input of the optional PHASE clause 23 | } 24 | \item{calctype}{ 25 | the character representation of the input of the optional CALCTYPE clause 26 | } 27 | \item{output}{ 28 | the character representation of the input of the optional OUTPUT clause 29 | } 30 | \item{null_handling}{ 31 | the character representation of the input of the optional specfication for null handling 32 | } 33 | \item{optional_operators}{ 34 | the character representation of the other operators that can be specified 35 | } 36 | \item{as}{ 37 | creates and alias 38 | } 39 | } 40 | \details{ 41 | %% ~~ If necessary, more details than the description above ~~ 42 | } 43 | \value{ 44 | a character representation of a query that can be passed into TdQuery to use the CalcMatrix table operator. 45 | } 46 | \references{ 47 | %% ~put references to the literature/web site here ~ 48 | } 49 | \author{ 50 | Erin Cole 51 | } 52 | \note{ 53 | %% ~~further notes~~ 54 | } 55 | 56 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 57 | 58 | \seealso{ 59 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 60 | } 61 | \examples{ 62 | on2 <- on(target= "select * from tab1") 63 | query <- td.CalcMatrix(selectPhrase="select session as ampkey, D1.* from TD_SYSFNLIB.calcmatrix", ons=on1, phase="LOCAL", as="D1") 64 | res <- tdQuery(query) 65 | print(res) 66 | } 67 | % Add one or more standard keywords, see file 'KEYWORDS' in the 68 | % R documentation directory. 69 | \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") 70 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 71 | -------------------------------------------------------------------------------- /man/td.ExecR.Rd: -------------------------------------------------------------------------------- 1 | \name{td.ExecR} 2 | \alias{td.ExecR} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{ 5 | ExecR Wrapper Function 6 | } 7 | \description{ 8 | This function is a wrapper function around the table operator ExecR. It generates a string that can be passed into the function tdQuery to make a query that uses ExecR. The Contract and Operator can be given as character vectors or read from files. In the latter case, the path to the file is given for Contract or Operator. The file(s) must include only R code, the contents of the files essentially get copied. Files paths can be specified by using relative paths from getwd() or the absolute path. 9 | } 10 | \usage{ 11 | td.ExecR(selectPhrase=string, ons=list(), returns=NULL, contract=NULL, operator=string, optional_operators=NULL) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{selectPhrase}{ 16 | a character that represents a select phrase 17 | } 18 | \item{ons}{ 19 | a list or character representation of on clauses 20 | } 21 | \item{returns}{ 22 | a character vector of a returns clause (e.g. returns <- c("col1 int", "col2 real")) 23 | } 24 | \item{contract}{ 25 | a file or character representation of a contract clause. 26 | } 27 | \item{operator}{ 28 | a file or character representation of an operator clause 29 | } 30 | \item{optional_operators}{ 31 | a character representation of any other needed operators 32 | } 33 | } 34 | \details{ 35 | %% ~~ If necessary, more details than the description above ~~ 36 | } 37 | \value{ 38 | A character representation of a query that will use the ExecR table operator when passed into the tdQuery function. 39 | } 40 | \references{ 41 | %% ~put references to the literature/web site here ~ 42 | } 43 | \author{ 44 | Erin Cole 45 | } 46 | \note{ 47 | %% ~~further notes~~ 48 | } 49 | 50 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 51 | 52 | \seealso{ 53 | \code{\link{on}} 54 | } 55 | \examples{ 56 | on1 <- on(target="select *", from="tab1", hash="c1", local_order="c2") 57 | query <- td.ExecR(selectPhrase="select distinct * from TD_SYSGPL.ExecR", ons=on1, contract="~/Documents/contract.txt", operator="~/Documents/operator.txt") 58 | res <- tdQuery(query) 59 | print(res) 60 | } 61 | % Add one or more standard keywords, see file 'KEYWORDS' in the 62 | % R documentation directory. 63 | \keyword{ ~kwd1 }% use one of RShowDoc("KEYWORDS") 64 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 65 | -------------------------------------------------------------------------------- /man/td.bincode.Rd: -------------------------------------------------------------------------------- 1 | \name{td.bincode} 2 | \alias{td.bincode} 3 | \title{ 4 | Create Table of Bincode Values 5 | } 6 | \description{ 7 | Generate a Teradata table of columns and the newly bincoded column. 8 | } 9 | \usage{ 10 | td.bincode(tdf, col, oTable, oDatabase = "", bins = 10) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | name of column to be bincoded. 18 | } 19 | \item{oTable}{ 20 | output table name. 21 | } 22 | \item{oDatabase}{ 23 | output database name. 24 | } 25 | \item{bins}{ 26 | number of groups to bin(break) column into. 27 | } 28 | } 29 | \details{ 30 | Create a new table with the same column name as the input but now with bincoded 31 | values. 32 | } 33 | \value{ 34 | td data frame that represents the new table created by bincode. 35 | } 36 | \examples{ 37 | 38 | \dontrun{ 39 | td.bincode(tdf, "age", "newBinTable", bins=12) # break age into 12 groups or bins 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/td.binomial.Rd: -------------------------------------------------------------------------------- 1 | \name{td.binomial} 2 | \alias{td.binomial} 3 | \title{ 4 | Binomial Test 5 | } 6 | \description{ 7 | Function to run binomial test against columns in Teradata. 8 | } 9 | \usage{ 10 | td.binomial(tdf, first, second, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{first}{ 17 | first column name. 18 | } 19 | \item{second}{ 20 | second column name. 21 | } 22 | \item{thresh}{ 23 | threshold value. Defaults to 0.05. 24 | } 25 | } 26 | \details{ 27 | The data for a binomial test is assumed to come from n independent trials, and have 28 | outcomes in either of two classes. The other assumption is that the probability of 29 | each outcome of each trial is the same, designated p. The values of the outcome could 30 | come directly from the data, where the value is always one of two kinds. 31 | } 32 | \value{ 33 | data frame with one row of binomial results. 34 | } 35 | \note{ 36 | Several statistical functions like this one use the Teradata Warehouse Miner 37 | statistical tables and they need to be installed to use this function. You can 38 | also set up tdMetadataDB once you know where they are installed otherwise they 39 | will be searched for. 40 | } 41 | 42 | \examples{ 43 | 44 | \dontrun{ 45 | td.binomial(tdf, "income", "age") 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /man/td.binomialsign.Rd: -------------------------------------------------------------------------------- 1 | \name{td.binomialsign} 2 | \alias{td.binomialsign} 3 | \title{ 4 | Binomial Sign Test 5 | } 6 | \description{ 7 | Function to run a binomial sign test on a Teradata column. 8 | } 9 | \usage{ 10 | td.binomialsign(tdf, column, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{column}{ 17 | column name. 18 | } 19 | \item{thresh}{ 20 | threshold value. Defaults to 0.05. 21 | } 22 | } 23 | \details{ 24 | Function that runs the binomial sign test on a particular column and returns its 25 | results. 26 | } 27 | \value{ 28 | data frame of one row of binomial sign results. 29 | } 30 | \note{ 31 | Several statistical functions like this one use the Teradata Warehouse Miner 32 | statistical tables and they need to be installed to use this function. You can 33 | also set up tdMetadataDB once you know where they are installed otherwise they 34 | will be searched for. 35 | } 36 | 37 | \examples{ 38 | 39 | \dontrun{ 40 | td.binomialsign(tdf, "age") 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/td.call.sp.Rd: -------------------------------------------------------------------------------- 1 | \name{td.call.sp} 2 | \alias{td.call.sp} 3 | \title{ 4 | Locate and call stored procedure 5 | } 6 | \description{ 7 | Function searches the Teradata system for stored procedures. 8 | } 9 | \usage{ 10 | td.call.sp() 11 | } 12 | \details{ 13 | This function allows you to find stored procedures on your Teradata system and 14 | run them via a console menu. You first search for the stored procedure you are 15 | looking for, select it, enter input parameters if any, and then it is called 16 | for you. 17 | } 18 | \value{ 19 | No output results 20 | } 21 | \examples{ 22 | 23 | \dontrun{ 24 | td.call.sp() #interactive console menu and data entry 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /man/td.cor.Rd: -------------------------------------------------------------------------------- 1 | \name{td.cor} 2 | \alias{td.cor} 3 | \title{ 4 | Correlation Matrix 5 | } 6 | \description{ 7 | Create a matrix of the correlation between numeric columns. 8 | } 9 | \usage{ 10 | td.cor(tdf) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | } 17 | \details{ 18 | Build a matrix of all columns in the td data frame. 19 | } 20 | \value{ 21 | Return a matrix of numeric correlation values. 22 | } 23 | \examples{ 24 | 25 | \dontrun{ 26 | td.cor(tdf[1:4]) #select only the numeric columns 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/td.cov.Rd: -------------------------------------------------------------------------------- 1 | \name{td.cov} 2 | \alias{td.cov} 3 | \title{ 4 | Covariance Matrix 5 | } 6 | \description{ 7 | Create a matrix of the covariance between numeric columns. 8 | } 9 | \usage{ 10 | td.cov(tdf) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | } 17 | \details{ 18 | Build a matrix of all columns in the td data frame. 19 | } 20 | \value{ 21 | Return a matrix of numeric covariance values. 22 | } 23 | \examples{ 24 | 25 | \dontrun{ 26 | td.cov(tdf[1:4]) #select only the numeric columns 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /man/td.dagostino.pearson.Rd: -------------------------------------------------------------------------------- 1 | \name{td.dagostino.pearson} 2 | \alias{td.dagostino.pearson} 3 | \title{ 4 | D'Agostino Pearson Test 5 | } 6 | \description{ 7 | Function to use D'Agostino Pearson Test 8 | } 9 | \usage{ 10 | td.dagostino.pearson(tdf, col, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | \item{thresh}{ 20 | threshold value. Defaults to 0.05. 21 | } 22 | } 23 | \details{ 24 | Run the D'Agostino Pearson test against the td data frame for a column. 25 | } 26 | \value{ 27 | data frame with one row of D'Agostino Pearson results. 28 | } 29 | \note{ 30 | Several statistical functions like this one use the Teradata Warehouse Miner 31 | statistical tables and they need to be installed to use this function. You can 32 | also set up tdMetadataDB once you know where they are installed otherwise they 33 | will be searched for. 34 | } 35 | 36 | \examples{ 37 | 38 | \dontrun{ 39 | td.dagostino.pearson(tdf,"income") 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{td.data.frame} 2 | \alias{td.data.frame} 3 | \title{ 4 | Teradata Data Frames 5 | } 6 | \description{ 7 | An R object that represents a Teradata table. The object initializes with certain 8 | information upon creation such as total number of rows and what the column names of 9 | the table are. 10 | } 11 | \usage{ 12 | td.data.frame(table, database = "") 13 | } 14 | \arguments{ 15 | \item{table}{ 16 | name of table in Teradata to point to. 17 | } 18 | \item{database}{ 19 | database where table resides. Defaults to current DATABASE on connection. 20 | } 21 | } 22 | \details{ 23 | This is the main object that stores the link between a Teradata table and the 24 | R environment. No data from the table is actually resident in the R system only 25 | some initial values of rows and columns are persisted and stored within the 26 | td data frame object. 27 | } 28 | \value{ 29 | Returns a td data frame. 30 | } 31 | \examples{ 32 | \dontrun{ 33 | 34 | tdf <- td.data.frame("customer") 35 | #pointer to customer table in current database 36 | tdf2 <- td.data.frame("customer", "otherDB") 37 | #pointer to customer table in database 'otherDB' 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /man/td.f.oneway.Rd: -------------------------------------------------------------------------------- 1 | \name{td.f.oneway} 2 | \alias{td.f.oneway} 3 | \title{ 4 | One way F Test 5 | } 6 | \description{ 7 | Function to produce One Way F Test. 8 | } 9 | \usage{ 10 | td.f.oneway(tdf, col1, col2, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col1}{ 17 | first column name to test. 18 | } 19 | \item{col2}{ 20 | second column name to test. 21 | } 22 | \item{thresh}{ 23 | threshold value. Default is 0.05. 24 | } 25 | } 26 | \details{ 27 | Fun the one way F Test on the td data frame and this column and return a data 28 | frame result of one row. 29 | } 30 | \value{ 31 | data frame of one row with F Test results. 32 | } 33 | \note{ 34 | Several statistical functions like this one use the Teradata Warehouse Miner 35 | statistical tables and they need to be installed to use this function. You can 36 | also set up tdMetadataDB once you know where they are installed otherwise they 37 | will be searched for. 38 | } 39 | \examples{ 40 | 41 | \dontrun{ 42 | td.f.oneway(tdf, "income", "age") 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /man/td.factanal.Rd: -------------------------------------------------------------------------------- 1 | \name{td.factanal} 2 | \alias{td.factanal} 3 | \title{ 4 | Factor Analysis 5 | } 6 | \description{ 7 | Run covariance matrix and send results into R factanal function. 8 | } 9 | \usage{ 10 | td.factanal(tdf, ...) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{\dots}{ 17 | conform to generic function and pass values like factors. 18 | } 19 | } 20 | \details{ 21 | Build a covariance matrix in Teradata and call factanal with matrix. ... is 22 | specified so you and send how many factors you'd like to the factanal function. 23 | } 24 | \value{ 25 | factor analysis report. 26 | } 27 | \examples{ 28 | 29 | \dontrun{ 30 | td.factanal(tdf[1:4]) #limit to certain columns in td data frame 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /man/td.freq.Rd: -------------------------------------------------------------------------------- 1 | \name{td.freq} 2 | \alias{td.freq} 3 | \title{ 4 | Frequency Analysis 5 | } 6 | \description{ 7 | Produce a frequency analysis of a column in a td data frame. 8 | } 9 | \usage{ 10 | td.freq(tdf, col, plot = TRUE, ...) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | \item{plot}{ 20 | whether or not to plot results. Default is TRUE. 21 | } 22 | \item{\dots}{ 23 | commands to pass on to plot if needed. 24 | } 25 | } 26 | \details{ 27 | If td data frame consists of only 1 column then that column is used for the 28 | frequency. If 'col' is supplied with a multi column td data frame then that 29 | column is used to get frequency values. 30 | } 31 | \value{ 32 | data frame of frequency results. 33 | } 34 | \examples{ 35 | 36 | \dontrun{ 37 | td.freq(tdf[3]) 38 | td.freq(tdf["age"]) 39 | td.freq(tdf, "age") 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/td.hist.Rd: -------------------------------------------------------------------------------- 1 | \name{td.hist} 2 | \alias{td.hist} 3 | \title{ 4 | Histograms 5 | } 6 | \description{ 7 | Generate a histogram of a column 8 | } 9 | \usage{ 10 | td.hist(tdf, col, breaks = 10, plot = TRUE, ...) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | \item{breaks}{ 20 | groups to break column into. 21 | } 22 | \item{plot}{ 23 | Whether to plot results or not. Default is TRUE. 24 | } 25 | \item{\dots}{ 26 | Allow other commands to be sent to plot. 27 | } 28 | } 29 | \details{ 30 | Function builds a histogram object from a Teradata table to represent that 31 | column. It can then plot the result or use as a histogram object. 32 | } 33 | \value{ 34 | A histogram object. 35 | } 36 | \examples{ 37 | 38 | \dontrun{ 39 | td.hist(tdf[3]) 40 | td.hist(tdf["age"]) 41 | td.hist(tdf, "age") 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /man/td.join.Rd: -------------------------------------------------------------------------------- 1 | \name{td.join} 2 | \alias{td.join} 3 | \title{ 4 | Join Tables in Teradata 5 | } 6 | \description{ 7 | Join tables in Teradata based on their td data frames and index values. 8 | } 9 | \usage{ 10 | td.join(tdf1, tdf2, oTable = "newJoinTable", oDatabase = "", index1 = "", index2 = "", joinType = "inner") 11 | } 12 | \arguments{ 13 | \item{tdf1}{ 14 | first td data frame of table one. 15 | } 16 | \item{tdf2}{ 17 | second td data fame of table two. 18 | } 19 | \item{oTable}{ 20 | output table name of result. 21 | } 22 | \item{oDatabase}{ 23 | output database name of result. 24 | } 25 | \item{index1}{ 26 | index columns to use for the join from table one. 27 | } 28 | \item{index2}{ 29 | index columns to use for the join from table two. 30 | } 31 | \item{joinType}{ 32 | join type. One of ("inner", "left outer", "right outer", "full outer"). 33 | } 34 | } 35 | \details{ 36 | Allow joining of columns from two Teradata tables. The columns in the td data frames 37 | are used as the new column names along with the index from the first table. If 38 | indices are missing the primary indices will be searched and used. 39 | } 40 | \value{ 41 | td data frame pointing to the new output table from the join. 42 | } 43 | \examples{ 44 | 45 | \dontrun{ 46 | td.join(tdf, tdf2, "myNewTable",index1=c("pidx1","pidx2"), index2=c("pidx1","pidx2")) 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /man/td.kmeans.Rd: -------------------------------------------------------------------------------- 1 | \name{td.kmeans} 2 | \alias{td.kmeans} 3 | \title{ 4 | K-Means Clustering 5 | } 6 | \description{ 7 | Perform k-means clustering on data in Teradata 8 | } 9 | \usage{ 10 | td.kmeans(x, centers, iter.max=10, nstart=1) 11 | } 12 | \arguments{ 13 | \item{x}{ 14 | td data frame 15 | } 16 | \item{centers}{ 17 | The number of clusters to produce. 18 | } 19 | \item{iter.max}{ 20 | The maximum number of iterations allowed. 21 | } 22 | \item{nstart}{ 23 | How many random sets should be chosen from which to select the initial centers. 24 | } 25 | } 26 | \details{ 27 | The data given by x(data in Teradata) is clustered by the k-means method, which aims 28 | partition the points into k groups such that the sum of squares from points to the 29 | assigned cluster centers is minimized. At the minimum, all cluster centers are at the 30 | mean of their Voronoi sets(the set of data points which are nearest to the cluster center). 31 | } 32 | \value{ 33 | An object of class "kmeans" which is a list with components: 34 | 35 | {cluster}{For a td data frame this is NULL due to no data rows being in memory.} 36 | {centers}{A matrix of cluster centers.} 37 | {withinss}{The within-cluster sum of squares for each cluster.} 38 | {size}{The number of points in each cluster.} 39 | There is a print method for this class. 40 | } 41 | \examples{ 42 | 43 | \dontrun{ 44 | tdf <- td.data.frame("customer") 45 | tkm <- td.kmeans(tdf, 3) 46 | tkm #print out kmeans class results 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /man/td.ks.Rd: -------------------------------------------------------------------------------- 1 | \name{td.ks} 2 | \alias{td.ks} 3 | \title{ 4 | Kolmogorov Smirnov Test 5 | } 6 | \description{ 7 | Run Kolmogorov Smirnov test against a Teradata table and column. 8 | } 9 | \usage{ 10 | td.ks(tdf, col, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name to test. 18 | } 19 | \item{thresh}{ 20 | threshold value. Defaults to 0.05. 21 | } 22 | } 23 | \details{ 24 | Find KS statistics from a table and column in Teradata. 25 | } 26 | \value{ 27 | data frame with one row of test results. 28 | } 29 | \note{ 30 | Several statistical functions like this one use the Teradata Warehouse Miner 31 | statistical tables and they need to be installed to use this function. You can 32 | also set up tdMetadataDB once you know where they are installed otherwise they 33 | will be searched for. 34 | } 35 | \examples{ 36 | 37 | \dontrun{ 38 | td.ks(tdf,"age") 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/td.lilliefors.Rd: -------------------------------------------------------------------------------- 1 | \name{td.lilliefors} 2 | \alias{td.lilliefors} 3 | \title{ 4 | Lilliefors Test 5 | } 6 | \description{ 7 | Function to use lilliefors test on table and column. 8 | } 9 | \usage{ 10 | td.lilliefors(tdf, col, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name to test. 18 | } 19 | \item{thresh}{ 20 | threshold value. Defaults to 0.05. 21 | } 22 | } 23 | \details{ 24 | Use statistical tables to generate the lilliefors test statistic for this 25 | td data frame and column. 26 | } 27 | \value{ 28 | data frame with one row of results. 29 | } 30 | \note{ 31 | Several statistical functions like this one use the Teradata Warehouse Miner 32 | statistical tables and they need to be installed to use this function. You can 33 | also set up tdMetadataDB once you know where they are installed otherwise they 34 | will be searched for. 35 | } 36 | \examples{ 37 | 38 | \dontrun{ 39 | td.lilliefors(tdf,"age") 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/td.merge.Rd: -------------------------------------------------------------------------------- 1 | \name{td.merge} 2 | \alias{td.merge} 3 | \title{ 4 | Merge Rows of Teradata Tables 5 | } 6 | \description{ 7 | Function to merge rows of two Teradata tables based on merge type. 8 | } 9 | \usage{ 10 | td.merge(tdf1, tdf2, oTable = "newMergeTable", oDatabase = "", mergeType = "union") 11 | } 12 | \arguments{ 13 | \item{tdf1}{ 14 | td data frame of table one. 15 | } 16 | \item{tdf2}{ 17 | td data frame of table two. 18 | } 19 | \item{oTable}{ 20 | output table name. 21 | } 22 | \item{oDatabase}{ 23 | output database name. 24 | } 25 | \item{mergeType}{ 26 | type of merge to perform. Values can be ("union","minus",and "intersect") 27 | } 28 | } 29 | \details{ 30 | Create a new output table based on the merge type between two td data frames. 31 | Each td data frame must consist of the same number of columns in order to merge 32 | correctly. 33 | } 34 | \value{ 35 | td data frame pointing to the output table in Teradata. 36 | } 37 | \examples{ 38 | 39 | \dontrun{ 40 | td.merge(tdf1, tdf2, "newTable") 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /man/td.mode.Rd: -------------------------------------------------------------------------------- 1 | \name{td.mode} 2 | \alias{td.mode} 3 | \title{ 4 | Mode Value of Column 5 | } 6 | \description{ 7 | Function to find the most frequent value of a column in a td data frame. 8 | } 9 | \usage{ 10 | td.mode(tdf, col) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | } 20 | \details{ 21 | Function goes out and gets the most frequent value or mode of a column in a 22 | td data frame and returns it. 23 | } 24 | \value{ 25 | specific column value for most frequent value. 26 | } 27 | \examples{ 28 | 29 | \dontrun{ 30 | td.mode(tdf,"age") 31 | td.mode(tdf[3]) 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /man/td.mwnkw.Rd: -------------------------------------------------------------------------------- 1 | \name{td.mwnkw} 2 | \alias{td.mwnkw} 3 | \title{ 4 | Mann-Whitney/Kruskal Wallis Test 5 | } 6 | \description{ 7 | Function to test column in a td data frame with MW/KW. 8 | } 9 | \usage{ 10 | td.mwnkw(tdf, col1, col2, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col1}{ 17 | first column to test. 18 | } 19 | \item{col2}{ 20 | second column to test. 21 | } 22 | \item{thresh}{ 23 | threshold value. Defaults to 0.05. 24 | } 25 | } 26 | \details{ 27 | Function to find the MW/KW test value of two columns in a td data frame. 28 | } 29 | \value{ 30 | data frame with MW/KW test results. 31 | } 32 | \note{ 33 | Several statistical functions like this one use the Teradata Warehouse Miner 34 | statistical tables and they need to be installed to use this function. You can 35 | also set up tdMetadataDB once you know where they are installed otherwise they 36 | will be searched for. 37 | } 38 | \examples{ 39 | 40 | \dontrun{ 41 | td.mwnkw(tdf,"income","age") 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /man/td.nullreplace.Rd: -------------------------------------------------------------------------------- 1 | \name{td.nullreplace} 2 | \alias{td.nullreplace} 3 | \title{ 4 | Replace Null Values 5 | } 6 | \description{ 7 | Function which replaces null values within a td data frame and column. 8 | } 9 | \usage{ 10 | td.nullreplace(tdf, col, oTable, oDatabase = "", rType = "literal", rVal = "0") 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | \item{oTable}{ 20 | output table name. 21 | } 22 | \item{oDatabase}{ 23 | output database name. 24 | } 25 | \item{rType}{ 26 | type of replacement. Valid values are ("literal","mean","mode", and "median"). 27 | } 28 | \item{rVal}{ 29 | value for literal replacement. 30 | } 31 | } 32 | \details{ 33 | Build new table with column name after replacement is done via rType. 34 | } 35 | \value{ 36 | td data frame pointing to new Teradata table with NULLs replaced. 37 | } 38 | \examples{ 39 | 40 | \dontrun{ 41 | td.nullreplace(tdf,"age","newReplaceTable", rVal="16") 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /man/td.overlap.Rd: -------------------------------------------------------------------------------- 1 | \name{td.overlap} 2 | \alias{td.overlap} 3 | \title{ 4 | Overlap 5 | } 6 | \description{ 7 | Function returns data frame which shows how the fields from table 1 overlap 8 | table 2's fields. 9 | } 10 | \usage{ 11 | td.overlap(tdf1, tdf2, fields1, fields2) 12 | } 13 | \arguments{ 14 | \item{tdf1}{ 15 | td data frame of table one. 16 | } 17 | \item{tdf2}{ 18 | td data frame of table two. 19 | } 20 | \item{fields1}{ 21 | fields to use for overlap from table one. 22 | } 23 | \item{fields2}{ 24 | fields to use for overlap from table two. 25 | } 26 | } 27 | \details{ 28 | Match up columns and see which values are contained in both tables, how many 29 | uniques there are between each other. 30 | } 31 | \value{ 32 | results showing a table of the overlapping values. 33 | } 34 | \examples{ 35 | 36 | \dontrun{ 37 | td.overlap(tdf, tdf2, c("i1","i2"), c("f1","f2")) # fields can be same or diff 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/td.quantiles.Rd: -------------------------------------------------------------------------------- 1 | \name{td.quantiles} 2 | \alias{td.quantiles} 3 | \title{ 4 | Quantile Values 5 | } 6 | \description{ 7 | Function to retrieve quantile values for td data frame and column. 8 | } 9 | \usage{ 10 | td.quantiles(tdf, col, qType = c("ter", "quar", "dec")) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | \item{qType}{ 20 | which type of quantile to bring back. Valid are ("ter", "quar", "dec") for 21 | tertiles, quartiles and deciles respectively. 22 | } 23 | } 24 | \details{ 25 | Gather quantile information from td data frame on this column. 26 | } 27 | \value{ 28 | data frame results of quantile values. 29 | } 30 | \examples{ 31 | 32 | \dontrun{ 33 | td.quantiles(tdf,"age") 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /man/td.rank.Rd: -------------------------------------------------------------------------------- 1 | \name{td.rank} 2 | \alias{td.rank} 3 | \title{ 4 | Rank 5 | } 6 | \description{ 7 | Function returns list of ranks from column. 8 | } 9 | \usage{ 10 | td.rank(tdf, col) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | } 20 | \details{ 21 | Return several rank values from the td data frame for this column. 22 | } 23 | \value{ 24 | data frame of one row with rank values. 25 | } 26 | \examples{ 27 | 28 | \dontrun{ 29 | td.rank(tdf,"age") 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /man/td.recode.Rd: -------------------------------------------------------------------------------- 1 | \name{td.recode} 2 | \alias{td.recode} 3 | \title{ 4 | Recode 5 | } 6 | \description{ 7 | Function to allow change values of a column to new values. 8 | } 9 | \usage{ 10 | td.recode(tdf, col, oTable, oDatabase = "", codes, other="same") 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | \item{oTable}{ 20 | output table name. 21 | } 22 | \item{oDatabase}{ 23 | output database name. 24 | } 25 | \item{codes}{ 26 | vector of value pairs. Pairs are current value followed by new value. 27 | Must be even number of elements in vector. 28 | } 29 | \item{other}{ 30 | what to do with values not in the codes vector. Valid are 31 | ("same", "null"). Values not in codes vector stay same or are null. 32 | } 33 | } 34 | \details{ 35 | Create a new output table in Teradata with the recoded column from this 36 | td data frame. 37 | } 38 | \value{ 39 | td data frame pointer to the new table created. 40 | } 41 | \examples{ 42 | 43 | \dontrun{ 44 | td.recode(tdf,"marital_status","newCustomer",codes=c("1","S","2","M")) 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /man/td.rescale.Rd: -------------------------------------------------------------------------------- 1 | \name{td.rescale} 2 | \alias{td.rescale} 3 | \title{ 4 | Rescale Values of Column 5 | } 6 | \description{ 7 | Function rescaled values of a td data frame column. 8 | } 9 | \usage{ 10 | td.rescale(tdf, col, oTable, oDatabase = "", lower = 0, upper = 1) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | \item{oTable}{ 20 | output table name. 21 | } 22 | \item{oDatabase}{ 23 | output database name. 24 | } 25 | \item{lower}{ 26 | lower bound to rescale to. 27 | } 28 | \item{upper}{ 29 | upper bound to rescale to. 30 | } 31 | } 32 | \details{ 33 | Create a new output table of a column in this td data frame. This function 34 | allows you to rescale a column. 35 | } 36 | \value{ 37 | td data frame pointing to new output table. 38 | } 39 | \examples{ 40 | 41 | \dontrun{ 42 | td.rescale(tdf,"age","newTable") 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /man/td.sample.Rd: -------------------------------------------------------------------------------- 1 | \name{td.sample} 2 | \alias{td.sample} 3 | \title{ 4 | Sample Rows 5 | } 6 | \description{ 7 | Function to allow table a sample from a Teradata table. 8 | } 9 | \usage{ 10 | td.sample(tdf, sizes = missing, oTable = "", oDatabase = "") 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{sizes}{ 17 | size specification for the sample or samples you'd like to take. 18 | } 19 | \item{oTable}{ 20 | output table name. 21 | } 22 | \item{oDatabase}{ 23 | output database name. 24 | } 25 | } 26 | \details{ 27 | Function can draw one or more samples from a td data frame table. Sizes can be 28 | integer or decimal values under 1. With multiple samples you will get another 29 | column called sampleid so you can distinguish. If no output table is specified 30 | you will get a data frame with your samples back. 31 | } 32 | \value{ 33 | td data frame pointing new sample table. 34 | } 35 | \examples{ 36 | 37 | \dontrun{ 38 | td.sample(tdf,1000,"newSample") 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/td.shapiro.wilk.Rd: -------------------------------------------------------------------------------- 1 | \name{td.shapiro.wilk} 2 | \alias{td.shapiro.wilk} 3 | \title{ 4 | Shapiro Wilk 5 | } 6 | \description{ 7 | Function to run Shapiro Wilk test against td data frame and column. 8 | } 9 | \usage{ 10 | td.shapiro.wilk(tdf, col, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | \item{thresh}{ 20 | threshold value. Default is 0.05. 21 | } 22 | } 23 | \details{ 24 | Function returns test value for Shapiro Wilk on td data frame and column. 25 | } 26 | \value{ 27 | data frame of one row with test results. 28 | } 29 | \note{ 30 | Several statistical functions like this one use the Teradata Warehouse Miner 31 | statistical tables and they need to be installed to use this function. You can 32 | also set up tdMetadataDB once you know where they are installed otherwise they 33 | will be searched for. 34 | } 35 | \examples{ 36 | 37 | \dontrun{ 38 | td.shapiro.wilk(tdf,"age") 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /man/td.sigmoid.Rd: -------------------------------------------------------------------------------- 1 | \name{td.sigmoid} 2 | \alias{td.sigmoid} 3 | \title{ 4 | Sigmoid Transformation 5 | } 6 | \description{ 7 | Function to output a sigmoid transformation for a column in a td data frame. 8 | } 9 | \usage{ 10 | td.sigmoid(tdf, col, oTable, oDatabase = "", sigmoidType = "logit") 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column name. 18 | } 19 | \item{oTable}{ 20 | output table name. 21 | } 22 | \item{oDatabase}{ 23 | output database name. 24 | } 25 | \item{sigmoidType}{ 26 | type of sigmoid. Valid values are ("logit","mlogit",and "tanh"). 27 | } 28 | } 29 | \details{ 30 | Create table of the sigmoid tranformation using the type on this td data frame 31 | and column. 32 | } 33 | \value{ 34 | td data frame pointing to the new table produced. 35 | } 36 | \examples{ 37 | 38 | \dontrun{ 39 | td.sigmoid(tdf,"age","newSigTable") 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/td.smirnov.Rd: -------------------------------------------------------------------------------- 1 | \name{td.smirnov} 2 | \alias{td.smirnov} 3 | \title{ 4 | Smirnov Test 5 | } 6 | \description{ 7 | Function to run Smirnov test on td data frame and columns. 8 | } 9 | \usage{ 10 | td.smirnov(tdf, col1, col2, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col1}{ 17 | first column of test. 18 | } 19 | \item{col2}{ 20 | second column of test. 21 | } 22 | \item{thresh}{ 23 | threshold value. Defaults to 0.05. 24 | } 25 | } 26 | \details{ 27 | Run Smirnov test and return one row for test. Test is run on td data frame 28 | and two input column names. 29 | } 30 | \value{ 31 | data frame of one row with test results. 32 | } 33 | \note{ 34 | Several statistical functions like this one use the Teradata Warehouse Miner 35 | statistical tables and they need to be installed to use this function. You can 36 | also set up tdMetadataDB once you know where they are installed otherwise they 37 | will be searched for. 38 | } 39 | \examples{ 40 | 41 | \dontrun{ 42 | td.smirnov(tdf,"income","age") 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /man/td.solve.Rd: -------------------------------------------------------------------------------- 1 | \name{td.solve} 2 | \alias{td.solve} 3 | \title{ 4 | Solve a system of equations 5 | } 6 | \description{ 7 | Function solves a system of equations via a matrix. 8 | } 9 | \usage{ 10 | td.solve(tdf, rhscols) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{rhscols}{ 17 | vector of column names to solve for against the other matrix columns. 18 | } 19 | } 20 | \details{ 21 | This function produces a correlation matrix from the columns that make up the 22 | td data frame. It then uses the 'solve' function in R to solve for the 23 | right hand side columns based on that matrix. 24 | } 25 | \value{ 26 | vector or matrix of solved coefficients. 27 | } 28 | \examples{ 29 | 30 | \dontrun{ 31 | td.solve(tdf, "churn") 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /man/td.stats.Rd: -------------------------------------------------------------------------------- 1 | \name{td.stats} 2 | \alias{td.stats} 3 | \title{ 4 | General Statistics 5 | } 6 | \description{ 7 | This function uses the td data frame object passed in and retrieves some 8 | statistics for a particular column. 9 | } 10 | \usage{ 11 | td.stats(tdf, col, which = "all", type = "population", group.by=NULL) 12 | } 13 | \arguments{ 14 | \item{tdf}{ 15 | td data frame. 16 | } 17 | \item{col}{ 18 | name of column. 19 | } 20 | \item{which}{ 21 | string or array of which statistics to return. Any of the follow are valid 22 | choices: ("cnt","min","max","mean","sum","uss","css","var","std","skew", 23 | "kurtosis","stderr","cvar"). You can also use "all" to retrieve them all. 24 | } 25 | \item{type}{ 26 | whether to return the statistic based on the population or sample 27 | } 28 | \item{group.by}{ 29 | td data frame of columns that are used to group your results. 30 | } 31 | } 32 | \details{ 33 | This function collects certain statistics from the Teradata table and returns them 34 | to the user via an R data frame. Count, minimum, maximum, mean, sum, uncorrected 35 | sum of squares, corrected sum of squares, variance, standard deviation, skewness, 36 | kurtosis, standard error, and coefficient of variance are statistics to choose from. 37 | You can also put a type of "all" to retrieve them all at once. 38 | } 39 | \value{ 40 | data frame object with 1 row and the stats you have selected 41 | } 42 | \examples{ 43 | 44 | \dontrun{ 45 | td.stats(tdf, "income", c("min","max","mean")) 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /man/td.t.paired.Rd: -------------------------------------------------------------------------------- 1 | \name{td.t.paired} 2 | \alias{td.t.paired} 3 | \title{ 4 | T Test Paired 5 | } 6 | \description{ 7 | Function to run a paired T Test 8 | } 9 | \usage{ 10 | td.t.paired(tdf, col1, col2, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col1}{ 17 | first column to test. 18 | } 19 | \item{col2}{ 20 | second column to test. 21 | } 22 | \item{thresh}{ 23 | threshold. Default value is 0.05 24 | } 25 | } 26 | \details{ 27 | The test is whether paired values have mean differences which are not significantly 28 | different from zero. It assumes differences are identically distributed normal 29 | random variables, and that they are independent.} 30 | \value{ 31 | Single row data frame with the T Test results 32 | } 33 | \examples{ 34 | 35 | \dontrun{ 36 | td.t.paired(tdf, "income", "age") 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /man/td.t.unpaired.Rd: -------------------------------------------------------------------------------- 1 | \name{td.t.unpaired} 2 | \alias{td.t.unpaired} 3 | \title{ 4 | T Test Unpaired 5 | } 6 | \description{ 7 | Function to run unpaired T Test 8 | } 9 | \usage{ 10 | td.t.unpaired(tdf, col1, col2, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col1}{ 17 | first column to test. 18 | } 19 | \item{col2}{ 20 | second column to test. 21 | } 22 | \item{thresh}{ 23 | threshold. Default value is 0.05 24 | } 25 | } 26 | \details{ 27 | The unpaired t test is similar to the paired test, but there is no correspondence between 28 | values of the samples. It assumes within each sample, values are identically distributed 29 | normal random variables, and that the two samples are independent of each other. 30 | } 31 | \value{ 32 | Single row data frame with the T Test results 33 | } 34 | \examples{ 35 | 36 | \dontrun{ 37 | td.t.unpaired(tdf, "income", "age") 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/td.t.unpairedi.Rd: -------------------------------------------------------------------------------- 1 | \name{td.t.unpairedi} 2 | \alias{td.t.unpairedi} 3 | \title{ 4 | T Test - Unpaired Indicator 5 | } 6 | \description{ 7 | Function to run unpaired indicator T Test 8 | } 9 | \usage{ 10 | td.t.unpairedi(tdf, col1, col2, thresh = 0.05) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col1}{ 17 | first column to test. 18 | } 19 | \item{col2}{ 20 | second column to test. 21 | } 22 | \item{thresh}{ 23 | threshold. Default value is 0.05 24 | } 25 | } 26 | \details{ 27 | This function selects the column of interest and a second indicator column which 28 | determines to which group the first variable belongs. If the indicator variable 29 | is negative or zero, it will be assigned to the first group; if it is positive, 30 | it will be assigned to the second group. 31 | } 32 | \value{ 33 | Single row data frame with the T Test results 34 | } 35 | \examples{ 36 | 37 | \dontrun{ 38 | td.t.unpairedi(tdf, "income", "age") 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/td.tapply.Rd: -------------------------------------------------------------------------------- 1 | \name{td.tapply} 2 | \alias{td.tapply} 3 | \title{ 4 | Apply a function over a database column 5 | } 6 | \description{ 7 | Apply a function to each column value, that is to each (non-empty) group of values given by a unique combination of the levels of certain factors. 8 | } 9 | \usage{ 10 | td.tapply(X, INDEX, FUN = NULL, asdf = FALSE, ...) 11 | } 12 | \arguments{ 13 | \item{X}{ 14 | td data frame of column to apply function to. 15 | } 16 | \item{INDEX}{ 17 | td data frame of the list of columns, each in same table as X. 18 | } 19 | \item{FUN}{ 20 | One of the following functions to be applied (sum, min, max, mean, td.values, and td.stats). 21 | } 22 | \item{asdf}{ 23 | If TRUE, the return value is left as a data frame object. Otherwise default is as an array. 24 | } 25 | \item{\dots}{ 26 | forward information. 27 | } 28 | } 29 | \value{ 30 | Array dimensioned by the INDEX containing the result of applying FUN to the data. If asdf = TRUE 31 | the result will instead be a data frame of the results. 32 | } 33 | \examples{ 34 | 35 | \dontrun{ 36 | td.tapply(tdf["income"], tdf["gender"], td.stats) 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /man/td.values.Rd: -------------------------------------------------------------------------------- 1 | \name{td.values} 2 | \alias{td.values} 3 | \title{ 4 | Values 5 | } 6 | \description{ 7 | Helps determine the nature and overall quality of the data 8 | } 9 | \usage{ 10 | td.values(tdf, col, group.by=NULL) 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame 15 | } 16 | \item{col}{ 17 | column name 18 | } 19 | \item{group.by}{ 20 | td data frame of columns that are used to group your results. 21 | } 22 | } 23 | \details{ 24 | Given a td data frame and the name of a column, the td.values analysis provides 25 | rows with non-null values, rows with value 0, rows with a positive value, 26 | rows with a negative value, number of unique values and the number of rows 27 | containing blanks in the given column based on the type of column. 28 | } 29 | \value{ 30 | Single row data frame with the values results 31 | } 32 | \examples{ 33 | 34 | \dontrun{ 35 | td.values(tdf,"income") 36 | td.values(tdf[3]) 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /man/td.wilcoxon.Rd: -------------------------------------------------------------------------------- 1 | \name{td.wilcoxon} 2 | \alias{td.wilcoxon} 3 | \title{ 4 | Wilcoxon Test 5 | } 6 | \description{ 7 | The Wilcoxon Signed Ranks Test is an alternative analogous to the t-test 8 | for correlated samples. 9 | } 10 | \usage{ 11 | td.wilcoxon(tdf, col1, col2, thresh = 0.05) 12 | } 13 | \arguments{ 14 | \item{tdf}{ 15 | td data frame. 16 | } 17 | \item{col1}{ 18 | first column to test. 19 | } 20 | \item{col2}{ 21 | second column to test. 22 | } 23 | \item{thresh}{ 24 | threshold. Default value is 0.05 25 | } 26 | } 27 | \details{ 28 | Given a td data frame and names of paired numeric columns, a Wilcoxon test is produced. 29 | The Wilcoxon tests whether a sample comes from a population with a specific mean or median. 30 | The null hypothesis is that the samples come from populations with the same mean or median. 31 | The alternative hypothesis is that the samples come from populations with different means 32 | or medians (two-tailed test), or that in addition the difference is in a specific direction 33 | (upper-tailed or lower-tailed tests). Output is a p-value, which when compared to the 34 | users threshold, determines whether the null hypothesis should be rejected. 35 | } 36 | \value{ 37 | Single row data frame with the Wilcoxon test results 38 | } 39 | \examples{ 40 | 41 | \dontrun{ 42 | td.wilcoxon(tdf, "income", "age") 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /man/td.zscore.Rd: -------------------------------------------------------------------------------- 1 | \name{td.zscore} 2 | \alias{td.zscore} 3 | \title{ 4 | Zscore Transformation 5 | } 6 | \description{ 7 | Function to create a column as a zscore transformation. 8 | } 9 | \usage{ 10 | td.zscore(tdf, col, oTable, oDatabase = "") 11 | } 12 | \arguments{ 13 | \item{tdf}{ 14 | td data frame. 15 | } 16 | \item{col}{ 17 | column to test. 18 | } 19 | \item{oTable}{ 20 | output table name. 21 | } 22 | \item{oDatabase}{ 23 | output database name. 24 | } 25 | } 26 | \details{ 27 | In a Z-Score transformation, a numeric column is transformed into its Z-score based 28 | on the mean value and standard deviation of the data in the column. It transforms 29 | each column value into the number of standard deviations from the mean value of the column. 30 | } 31 | \value{ 32 | returns a td data frame pointing to your new table created with your new column as the 33 | z score transformation. 34 | } 35 | \examples{ 36 | 37 | \dontrun{ 38 | td.zscore(tdf,"age","newCust") 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/tdClose.Rd: -------------------------------------------------------------------------------- 1 | \name{tdClose} 2 | \alias{tdClose} 3 | \title{ 4 | Close connection 5 | } 6 | \description{ 7 | Close connection to database. 8 | } 9 | \usage{ 10 | tdClose(x = tdConnection) 11 | } 12 | \arguments{ 13 | \item{x}{ 14 | connection to close. Defaults to tdConnection. 15 | } 16 | } 17 | \details{ 18 | Close the connection object. tdConnection is a global variable and is the default 19 | connection to close. 20 | } 21 | \examples{ 22 | 23 | \dontrun{ 24 | tdClose() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /man/tdConnect.Rd: -------------------------------------------------------------------------------- 1 | \name{tdConnect} 2 | \alias{tdConnect} 3 | \title{ 4 | Connect to Teradata database 5 | } 6 | \description{ 7 | Open up a channel to a Teradata database. 8 | } 9 | \usage{ 10 | tdConnect(dsn, uid = "", pwd = "", database = "", dType = "odbc") 11 | } 12 | \arguments{ 13 | \item{dsn}{ 14 | string containing the data source name to connect to. 15 | } 16 | \item{uid}{ 17 | string containing the user id. 18 | } 19 | \item{pwd}{ 20 | string containing the password. 21 | } 22 | \item{database}{ 23 | string containing the default database. 24 | } 25 | \item{dType}{ 26 | string containing the driver type: odbc(default) or jdbc 27 | } 28 | } 29 | \details{ 30 | Function uses RODBC to make a connection to a Teradata database. 31 | } 32 | \value{ 33 | returns an R channel 34 | } 35 | \examples{ 36 | 37 | \dontrun{ 38 | tdConnect("myDsn") 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/tdMetadataDB.Rd: -------------------------------------------------------------------------------- 1 | \name{tdMetadataDB} 2 | \alias{tdMetadataDB} 3 | \title{ 4 | Set metadata database 5 | } 6 | \description{ 7 | Function to set location of statistic tables. 8 | } 9 | \usage{ 10 | tdMetadataDB(database) 11 | } 12 | \arguments{ 13 | \item{database}{ 14 | name of database where metadata like statistics tables will be found. 15 | } 16 | } 17 | \details{ 18 | This function sets a global variable 'tdMetadata' which is used for certain 19 | statistical tests. When this value isn't present other functions will try 20 | and search for the tables in your Teradata system. This function helps 21 | reduce search queries. Sending a NULL value will remove this variable from 22 | the global list and clear it. 23 | } 24 | \value{ 25 | Returns the database name if set; otherwise NA. 26 | } 27 | \examples{ 28 | 29 | \dontrun{ 30 | tdMetadataDB("MetaDB") 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /man/tdQuery.Rd: -------------------------------------------------------------------------------- 1 | \name{tdQuery} 2 | \alias{tdQuery} 3 | \title{ 4 | Query Teradata Database 5 | } 6 | \description{ 7 | Send a query to the Teradata Database and get a data frame back. This call is a 8 | wrapper of the sqlQuery function using the global tdConnection property. 9 | } 10 | \usage{ 11 | tdQuery(q, ...) 12 | } 13 | \arguments{ 14 | \item{q}{ 15 | An sql query. 16 | } 17 | \item{\dots}{ 18 | dots to pass along to sqlQuery for other attributes 19 | } 20 | } 21 | \details{ 22 | This function allows the user to query the Teradata system without always having 23 | to specify the connection. It uses the global connection tdConnection set in 24 | tdConnect. 25 | } 26 | \value{ 27 | data frame result for row returning queries. "No Data" returned for non row 28 | returning queries. 29 | } 30 | \examples{ 31 | 32 | \dontrun{ 33 | 34 | df <- tdQuery("SELECT * FROM customer") 35 | #returns data frame object with all rows and columns from customer table 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /man/teradataR-package.Rd: -------------------------------------------------------------------------------- 1 | \name{teradataR-package} 2 | \alias{teradataR-package} 3 | \alias{teradataR} 4 | \docType{package} 5 | \title{ 6 | Allow access to Teradata via R 7 | } 8 | \description{ 9 | This package is designed to allow users of R to interact with a Teradata database. 10 | Users can use many statistical functions directly against the Teradata system 11 | without having to extract the data into memory. 12 | } 13 | \details{ 14 | \tabular{ll}{ 15 | Package: \tab teradataR\cr 16 | Type: \tab Package\cr 17 | Version: \tab 1.0\cr 18 | Date: \tab 2010-10-11\cr 19 | License: \tab GPL (>= 2)\cr 20 | LazyLoad: \tab yes\cr 21 | } 22 | } 23 | \author{ 24 | Todd Brye 25 | 26 | Maintainer: 27 | } 28 | 29 | \keyword{ package } 30 | \examples{ 31 | 32 | \dontrun{ 33 | tdConnect("tdSystem") 34 | tdf <- td.data.frame("transactions") 35 | td.stats(tdf["column"]) 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /man/z[.td.data.frame.Rd: -------------------------------------------------------------------------------- 1 | \name{[.td.data.frame} 2 | \alias{[.td.data.frame} 3 | \title{ 4 | Extract Teradata Data Frame 5 | } 6 | \description{ 7 | Allow manipulation and extraction of a td data frame. 8 | } 9 | \usage{ 10 | \method{[}{td.data.frame}(x, i, j) 11 | } 12 | \arguments{ 13 | \item{x}{ 14 | td data frame. 15 | } 16 | \item{i}{ 17 | element to extract 18 | } 19 | \item{j}{ 20 | element to extract 21 | } 22 | } 23 | \details{ 24 | This overloaded function operates almost exactly like a data frame extract. It 25 | can be used to reduce the number of columns by using the index values. One 26 | noticeable difference is that a td data frame has no actual data in the client. 27 | This means that row operations don't extract certain rows like a data frame object. 28 | You must use td.sample if you wish to alter table sizes. 29 | } 30 | \value{ 31 | td data frame of new column dimensions. 32 | } 33 | \examples{ 34 | 35 | \dontrun{ 36 | tdf[3] #returns td data frame with just column 3 37 | tdf["age"] #returns td data frame with column age 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /test/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Teradata/teradataR/453518bf036d9edeee24779a62d14a0033adc6f6/test/.DS_Store -------------------------------------------------------------------------------- /test/basicContract.txt: -------------------------------------------------------------------------------- 1 | library(tdr); -------------------------------------------------------------------------------- /test/basicOperator.txt: -------------------------------------------------------------------------------- 1 | library(tdr); -------------------------------------------------------------------------------- /test/setup.R: -------------------------------------------------------------------------------- 1 | # Although this file is an R file, for the sake of consistency with the other 2 | # files, the code is in SQL. It is all commented out so that the file does not 3 | # produce compile errors. Please copy and past the desired code into bteq in 4 | # order to make the needed tables 5 | 6 | # Table Name: numTab 7 | # This table is used for testing numeric functions. It works with the tests for 8 | # AVG(), DECODE(), POWER(), and TO_CHAR(). 9 | # 10 | # drop table numTab; 11 | # drop table numTab2; 12 | # create table numTab ( 13 | # c1 integer, 14 | # c2 integer, 15 | # c3 character(1)); 16 | # 17 | # insert into numTab (c1, c2, c3) values (5, 2, '9'); 18 | # insert into numTab (c1, c2, c3) values (8, 3, '9'); 19 | # insert into numTab (c1, c2, c3) values (2, 4, '9'); 20 | # insert into numTab (c1, c2, c3) values (6, 3, '9'); 21 | # insert into numTab (c1, c2, c3) values (3, 2, '9'); 22 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23 | # Table Name: negNums 24 | # This table is used for testing the SIGN() function 25 | # 26 | # drop table negNums; 27 | # drop table negNums2; 28 | # create table negNums ( 29 | # c1 integer); 30 | # 31 | # insert into negNums values(-11); 32 | # insert into negNums values(3); 33 | # insert into negNums values(-2); 34 | # insert into negNums values(4); 35 | # insert into negNums values(555); 36 | # insert into negNums values(0); 37 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 38 | # Table Name: test 39 | # This table is used for testing functions for character manipulation. It 40 | # works with the tests for CHR(), INITCAP(), and NGRAM(). 41 | # 42 | # drop table test; 43 | # drop table test2; 44 | # create table test ( 45 | # c1 integer, 46 | # c2 varchar(100), 47 | # c3 varchar(100)); 48 | # 49 | # insert into test (c1, c2, c3) values (1, 'mouse', 'house'); 50 | # insert into test (c1, c2, c3) values (2, 'fork', 'spoon'); 51 | # insert into test (c1, c2, c3) values (3, 'ball', 'bat'); 52 | # insert into test (c1, c2, c3) values (4, 'robot', 'human'); 53 | # insert into test (c1, c2, c3) values (5, 'cat', 'dog'); 54 | # insert into test (c1, c2, c3) values (6, 'horse', 'force'); 55 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 | # Table Name: charTab 57 | # This table is used for testing functions that search characters under 58 | # certain conditions. It works with tests for INSTR(), OREPLACE(), OTRANSLATE(). 59 | # 60 | # drop table charTab; 61 | # drop table charTab2; 62 | # create table charTab ( 63 | # c1 varchar(50), 64 | # c2 varchar(50), 65 | # c3 varchar(50), 66 | # c4 varchar(50), 67 | # c5 varchar(50)); 68 | # 69 | # insert into charTab (c1, c2, c3, c4, c5) values ('explore', 'lo', 'xx', 'e', 'z'); 70 | # insert into charTab (c1, c2, c3, c4, c5) values ('interrupt', 'ter', 'xyz', 'u', 'z'); 71 | # insert into charTab (c1, c2, c3, c4, c5) values ('disappear', 'ar', 'yy', 's', 'z'); 72 | # insert into charTab (c1, c2, c3, c4, c5) values ('factor', 'ac', 'xy', 'c', 'z'); 73 | # insert into charTab (c1, c2, c3, c4, c5) values ('appreciate', 'pp', 'xx', 'r', 'z'); 74 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 75 | # Table Name: padTab 76 | # This table is used for testing functions that manipulate white space. It 77 | # works with tests for LPAD(), LTRIM(), RPAD(), and RTRIM(). 78 | # 79 | # drop table padTab; 80 | # drop table padTab2; 81 | # create table padTab ( 82 | # c1 varchar(10), 83 | # c2 varchar(10), 84 | # c3 varchar(10)); 85 | # 86 | # insert into padTab (c1, c2, c3) values ('Emily ',' Emily', 'Emily'); 87 | # insert into padTab (c1, c2, c3) values ('Daisy ', ' Daisy', 'Daisy'); 88 | # insert into padTab (c1, c2, c3) values ('Hank ', ' Hank', 'Hank'); 89 | # insert into padTab (c1, c2, c3) values ('Amy ', ' Amy', 'Amy'); 90 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 91 | # Table Name: numManip 92 | # This table is used for testing functions that manupulate numbers. It works 93 | # with tests for TO_NUMBER() and TRUNC(). 94 | # 95 | # 96 | # drop table numManip; 97 | # drop table numManip2; 98 | # create table numManip ( 99 | # c1 character(5), 100 | # c2 number); 101 | # 102 | # insert into numManip (c1, c2) values ('1', 555.3); 103 | # insert into numManip (c1, c2) values ('2', 8.289); 104 | # insert into numManip (c1, c2) values ('3', 48.1); 105 | # insert into numManip (c1, c2) values ('4', 17.06); 106 | # insert into numManip (c1, c2) values ('5', 13.99); -------------------------------------------------------------------------------- /test/testCHR.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "test" 2 | # c1 c2 c3 3 | # ---------- ----------- ---------- 4 | # 5 cat dog 5 | # 4 robot human 6 | # 6 horse force 7 | # 3 ball bat 8 | # 1 mouse house 9 | # 2 fork spoon 10 | tdf <- td.data.frame("test") 11 | tdf["c4"] <- CHR(tdf["c1"]) 12 | as.td.data.frame(tdf, tableName="test2") 13 | 14 | # the resulting table is below, called "test2" 15 | # c1 c2 c3 c4 16 | # ---------- ----------- ---------- --------- 17 | # 5 cat dog 18 | # 4 robot human 19 | # 6 horse force 20 | # 3 ball bat 21 | # 1 mouse house 22 | # 2 fork spoon 23 | 24 | #Although the resulting table does not seem to give the expected output, the same output occurs in bteq and in RStudio. 25 | #Further testing is recommended -------------------------------------------------------------------------------- /test/testCalcMatrix.R: -------------------------------------------------------------------------------- 1 | #on1 <- on(target="select var1, var2, var3, var4, var5", from="testCM") 2 | #res1 <- td.CalcMatrix(selectPhrase='select * from TD_SYSFNLIB.calcmatrix', ons=on1, phase="local", as= "D1") 3 | #query1 <- tdQuery(res1) 4 | #print(query1) 5 | 6 | #on2 <- on(target= "select * from numbers") 7 | #res2 <- td.CalcMatrix(selectPhrase="select session as ampkey, D1.* from TD_SYSFNLIB.calcmatrix", ons=on2, phase="LOCAL", as="D1") 8 | #query2 <- tdQuery(res2) 9 | #print(query2) 10 | 11 | #on3 <- on(target="select var1, var2, var3, var4, var5 from TestCM2") 12 | #res4 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on3, phase="local", as="D1") 13 | #query4 <- tdQuery(res4) 14 | #print(query4) 15 | 16 | #on4 <- on(target ="select * from TestCMLocal", hash="p") 17 | #res5 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on4, phase="combine", calctype="sscp", output="columns", as="D1") 18 | #query5 <- tdQuery(res5) 19 | #print(query5) 20 | 21 | #on5 <- on(target ="select * from TestCMLocal", hash="p") 22 | #res6 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on5, phase="combine", calctype="CSSCP", output="columns", as="D1") 23 | #query6 <- tdQuery(res6) 24 | #print(query6) 25 | 26 | #on6 <-on(target="select * from TestCMLocal", hash="p") 27 | #res7 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on6, phase="combine", calctype="COV", output="columns", as="D1") 28 | #query7 <- tdQuery(res7) 29 | #print(query7) 30 | 31 | #on7 <- on(target="select * from TestCMLocal", hash="p") 32 | #res8 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on7, phase="combine", calctype="COR", output="varbyte", as="D1") 33 | #query8 <- tdQuery(res8) 34 | #print(query8) 35 | 36 | #on8 <- on(target="select * from TestCMLocal", hash="p") 37 | #res9 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on8, phase="combine", calctype="SSCP", output="varbyte", as="D1") 38 | #query9 <- tdQuery(res9) 39 | #print(query9) 40 | 41 | #on9 <- on(target="select var1, var2, var3, var4, var5 from TestCMNull") 42 | #res10 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on9, phase="local", null_handling="ignore", as="D1") 43 | #query10 <- tdQuery(res10) 44 | #print(query10) 45 | 46 | #on10 <- on(target="select var1, var2, var3, var4, var5", from="TestCMNull") 47 | #res11 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on10, phase="local", null_handling="zero", as="D1") 48 | #query11 <- tdQuery(res11) 49 | #print(query11) 50 | 51 | #on11 <- on(target="select p, var1, var2, var3, var4, var5 from TestCM_Mult", local_order="p") 52 | #res12 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on11, phase="local", as="D1") 53 | #query12 <- tdQuery(res12) 54 | #print(query12) 55 | 56 | #on12 <- on(target="select p, var1, var2, var3, var4, var5 from TestCM_Mult", local_order="p") 57 | #res13 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on12, phase="local", as="D1") 58 | #query13 <- tdQuery(res13) 59 | #print(query13) 60 | 61 | #on14 <- on(target="select p, var1, var2, var3, var4,var5", from="TESTCM_Mult", local_order = "p") 62 | #sub1 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on14, phase="local", as="D1") 63 | #on15 <- on(target=sub1, hash="p", local_order="p") 64 | #res14 <- td.CalcMatrix(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on15, phase="combine", calctype="esscp", as="D2") 65 | #query14 <- tdQuery(res14) 66 | #print(query14) 67 | -------------------------------------------------------------------------------- /test/testDECODE.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "numTab" 2 | # 3 | # c1 c2 c3 4 | # ----------- ----------- -- 5 | # 5 2 9 6 | # 6 3 9 7 | # 3 2 9 8 | # 8 3 9 9 | # 2 4 9 10 | 11 | tdf <- td.data.frame("numTab") 12 | tdf["c4"] <- DECODE(tdf["c1"], default='none', 1, 'Alpha', 2, 'Bravo', 3, 'Charlie', 4, 'Delta', 5, 'Echo') 13 | as.td.data.frame(tdf, tableName="numTab2") 14 | 15 | # This is the resulting table, called "numTab2" 16 | # c1 c2 c3 c4 17 | # ----------- ----------- -- ------- 18 | # 5 2 9 Echo 19 | # 6 3 9 none 20 | # 3 2 9 Charlie 21 | # 8 3 9 none 22 | # 2 4 9 Bravo 23 | 24 | # To verify each entry of c4: 25 | res1 = tdQuery("select c4 from numTab2 where c1=5") == "Echo" 26 | stopifnot(res1) 27 | 28 | res2 = tdQuery("select c4 from numTab2 where c1=6") == "none" 29 | stopifnot(res2) 30 | 31 | res3 = tdQuery("select c4 from numTab2 where c1=3") == "Charlie" 32 | stopifnot(res3) 33 | 34 | res4 = tdQuery("select c4 from numTab2 where c1=8") == "none" 35 | stopifnot(res4) 36 | 37 | res5 = tdQuery("select c4 from numTab2 where c1=2") == "Bravo" 38 | stopifnot(res5) -------------------------------------------------------------------------------- /test/testExecR.R: -------------------------------------------------------------------------------- 1 | source("~/Documents/RRR/Code/ExecR.R") 2 | 3 | #on1 <- on(target= "select * from test", hash="c1", local_order="c2") 4 | #onList <- list(on1) 5 | #res1 <- td.ExecR(selectPhrase="select distinct * from TD_SYSGPL.ExecR", ons=onList, contract="~/Documents/RRR/contract.txt", operator="~/Documents/RRR/Test/basicOperator.txt", optional_operators="keeplog(1)\nlogdebug(1)") 6 | #query1 <- tdQuery(res1) 7 | #print(query1) 8 | 9 | #on2 <- on(target="test", dimension="") 10 | #onList2 <-list( on3) 11 | #print(onList2) 12 | #res2 <- td.ExecR(selectPhrase="select distinct * from TD_SYSGPL.ExecR", ons=onList2, contract="~/Documents/RRR/Contract.txt", operator="~/Documents/RRR/Test/basicOperator.txt", optional_operators="keeplog(1)\nlogdebug(1)") 13 | #query2 <- tdQuery(res2) 14 | #print(query2) 15 | 16 | #on4 <- on(target="numbers", partition="1") 17 | #on5 <- on(target="numbers", dimension="") 18 | #onList3 <- list(on4, on5) 19 | #res3 <- td.ExecR(selectPhrase="select distinct * from TD_SYSGPL.ExecR", ons=onList3, contract="~/Documents/RRR/Contract.txt", operator="~/Documents/RRR/Test/basicOperator.txt", optional_operators=NULL) 20 | #query3 <- tdQuery(res3) 21 | #print(query3) 22 | 23 | #on6 <- on(target="select 1", partition="1") 24 | #on7 <- on(target="select * from test", dimension = "") 25 | #onList4 <- list(on6, on7) 26 | #res4 <- td.ExecR(selectPhrase = "select * from TD_SYSGPL.ExecR", ons=onList4, contract="~/Documents/RRR/Contract.txt", operator="~/Documents/RRR/Test/basicOperator.txt", optional_operators = "keeolog(1)\nlogdebug(1)") 27 | #query4 <- tdQuery(res4) 28 | #print(query4) 29 | 30 | #on8 <- on(target="select * from test", as="test") 31 | #res5 <- td.ExecR(selectPhrase = "select * from TD_SYSGPL.ExecR", ons=on8, contract= "~/Documents/RRR/Contract.txt", operator="~/Documents/RRR/Test/basicOperator.txt", optional_operators="keeplog(1)\nlogdebug(1)") 32 | #query5 <- tdQuery(res5) 33 | #print(query5) 34 | 35 | #on9 <- on(target="test", as="test1", partition="c1") 36 | #on10 <- on(target ="test", as="test2", dimension="") 37 | #onList5 <- list(on9, on10) 38 | #res6 <- td.ExecR(selectPhrase="select distinct * from TD_SYSGPL.ExecR", ons=onList5, contract= "~/Documents/RRR/Contract.txt", operator="~/Documents/RRR/Test/basicOperator.txt", optional_operators="keeplog(1)\nlogdebug(1)") 39 | #query6 <- tdQuery(res6) 40 | #print(query6) 41 | 42 | #on11 <- on(target="test", as="test1", partition="c1") 43 | #on12 <- on(target="test", as="test2", dimension=" ") 44 | #on13 <- on(target="test", as="test3", dimension=" ") 45 | #onList6 <- list(on11, on12, on13) 46 | #res7 <- td.ExecR(selectPhrase="select distinct * from TD_SYSGPL.ExecR", ons=onList6, contract="~/Documents/RRR/Contract.txt", operator="~/Documents/RRR/Test/basicOperator.txt", optional_operators = "keeplog(1)\nlogdebug(1)") 47 | #query7 <- tdQuery(res7) 48 | #print(query7) 49 | 50 | #on14 <- on(target="select *", from ="test", hash="c1", local_order="c1") 51 | #res8 <- td.ExecR(selectPhrase="select distinct * from TD_SYSGPL.ExecR", ons=on14, contract="~/Documents/RRR/Contract.txt", operator="~/Documents/RRR/Test/basicOperator.txt") 52 | #query8 <- tdQuery(res8) 53 | #print(query8) 54 | 55 | #on15 <- on(target= "select * from test", partition="c1") 56 | #res9 <- td.ExecR(selectPhrase="select * from TD_SYSGPL.ExecR", ons=on15, contract="~/Documents/RRR/Contract.txt", operator="~/Documents/RRR/Test/basicOperator.txt", optional_operators="keeplog(1)\nlogdebug(1)") 57 | #query9 <- tdQuery(res9) 58 | #print(query9) 59 | 60 | #on16 <- on(target="twm_customer_analysis", partition="marital_status") 61 | #res10 <- td.ExecR(selectPhrase="select * from TD_SYSGPL.ExecR", ons=on16, returns="~/Documents/RRR/returns.txt", operator="~/Documents/RRR/Test/basicOperator.txt", optional_operators="keeplog(1)\nlogdebug(1)") 62 | #query10 <- tdQuery(res10) 63 | #print(query10) 64 | 65 | #test case does not work 66 | #on17 <- on(target="select * from test") 67 | #res11 <- td.ExecR(selectPhrase="select * from TD_SYSGPL.ExecR", ons=on17, returns="testout", operator="~/Documents/RRR/Test/basicOperator.txt") 68 | #query11 <- tdQuery(res11) 69 | #print(query11) 70 | 71 | #test case missing contract clause. Should get an error 72 | #on18 <- on(target="select *", from="test") 73 | #res12 <- td.ExecR(selectPhrase="select * from TD_SYSGPL.ExecR", ons=on18, operator="~/Documents/RRR/Test/basicOperator.txt") 74 | #query12 <- tdQuery(res12) 75 | #print(query12) -------------------------------------------------------------------------------- /test/testINITCAP.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "test" 2 | # c1 c2 c3 3 | # ---------- ----------- ---------- 4 | # 5 cat dog 5 | # 4 robot human 6 | # 6 horse force 7 | # 3 ball bat 8 | # 1 mouse house 9 | # 2 fork spoon 10 | # the R code is below: 11 | tdf <- td.data.frame("test") 12 | tdf["c4"] <- INITCAP(tdf["c2"]) 13 | as.td.data.frame(tdf, tableName="test2") 14 | 15 | # Below are the results of the table, when you type "select * from test2" 16 | # c1 c2 c3 c4 17 | # ---------- ----------- ---------- --------- 18 | # 5 cat dog Cat 19 | # 4 robot human Robot 20 | # 6 horse force Horse 21 | # 3 ball bat Ball 22 | # 1 mouse house Mouse 23 | # 2 fork spoon Fork 24 | # 25 | # To verify each entry of test2 26 | res1 = tdQuery("select c4 from test2 where c1=5") == "Cat" 27 | stopifnot(res1) 28 | 29 | res2 = tdQuery("select c4 from test2 where c1=4") == "Robot" 30 | stopifnot(res2) 31 | 32 | res3 = tdQuery("select c4 from test2 where c1=6") == "Horse" 33 | stopifnot(res3) 34 | 35 | res4 = tdQuery("select c4 from test2 where c1=3") == "Ball" 36 | stopifnot(res4) 37 | 38 | res5 = tdQuery("select c4 from test2 where c1=1") == "Mouse" 39 | stopifnot(res5) 40 | 41 | res6 = tdQuery("select c4 from test2 where c1=2") == "Fork" 42 | stopifnot(res6) -------------------------------------------------------------------------------- /test/testINSTR.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "charTab" 2 | # c1 c2 c3 c4 c5 3 | # ---------- ---- ------- --------- --------- 4 | # explore lo xx e z 5 | # interrupt ter xyz u z 6 | # disappear ar yy s z 7 | # factor ac xy c z 8 | # appreciate pp xx r z 9 | 10 | tdf <- td.data.frame("charTab") 11 | tdf["c6"] <- INSTR(tdf["c1"], tdf["c2"]) 12 | as.td.data.frame(tdf, tableName="charTab2") 13 | 14 | # This is the resulting table, called "charTab2" 15 | # c1 c2 c3 c4 c5 c6 16 | # ---------- ---- ------- --------- --------- --------- 17 | # explore lo xx e z 4 18 | # interrupt ter xyz u z 3 19 | # disappear ar yy s z 8 20 | # factor ac xy c z 2 21 | # appreciate pp xx r z 2 22 | 23 | # While running the equivalent code in bteq produces the same table, this test does not seem to give the expected output 24 | # I recommend further testing. -------------------------------------------------------------------------------- /test/testLPAD.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "padTab" 2 | # c1 c2 c3 3 | # --------------- --------------- --------------- 4 | # Emily Emily Emily 5 | # Daisy Daisy Daisy 6 | # Hank Hank Hank 7 | # Amy Amy Amy 8 | # 9 | # the R code is below: 10 | tdf <- td.data.frame("padTab") 11 | tdf["c4"] <- LPAD(tdf["c3"], 15, "x") 12 | as.td.data.frame(tdf, tableName="padTab2") 13 | 14 | # Below are the results of the table, when you type "select * from padTab2" 15 | # c1 c2 c3 c4 16 | # --------------- --------------- --------------- --------------------------- 17 | # Emily Emily Emily xxxxxxxxxxEmily 18 | # Daisy Daisy Daisy xxxxxxxxxxDaisy 19 | # Hank Hank Hank xxxxxxxxxxxHank 20 | # Amy Amy Amy xxxxxxxxxxxxAmy 21 | 22 | # To verify each entry of c4: 23 | res1 = tdQuery("select c4 from padTab2 where c3='Emily'") == "xxxxxxxxxxEmily" 24 | stopifnot(res1) 25 | 26 | res2 = tdQuery("select c4 from padTab2 where c3='Daisy'") == "xxxxxxxxxxDaisy" 27 | stopifnot(res2) 28 | 29 | res3 = tdQuery("select c4 from padTab2 where c3='Hank'") == "xxxxxxxxxxxHank" 30 | stopifnot(res3) 31 | 32 | res4 = tdQuery("select c4 from padTab2 where c3='Amy'") == "xxxxxxxxxxxxAmy" 33 | stopifnot(res4) -------------------------------------------------------------------------------- /test/testLTRIM.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "padTab" 2 | # c1 c2 c3 3 | # --------------- --------------- --------------- 4 | # Emily Emily Emily 5 | # Daisy Daisy Daisy 6 | # Hank Hank Hank 7 | # Amy Amy Amy 8 | 9 | tdf <- td.data.frame("padTab") 10 | tdf["c4"] <- LTRIM(tdf["c2"]) 11 | as.td.data.frame(tdf, tableName="padTab2") 12 | 13 | #this is the resulting table caled "padTab2" 14 | # c1 c2 c3 c4 15 | # ---------- ---------- ---------- ---------- 16 | # Emily Emily Emily Emily 17 | # Daisy Daisy Daisy Daisy 18 | # Hank Hank Hank Hank 19 | # Amy Amy Amy Amy 20 | 21 | res1 = tdQuery("select c4 from padTab2 where c3='Emily'") == "Emily" 22 | stopifnot(res1) 23 | 24 | res2 = tdQuery("select c4 from padTab2 where c3='Daisy'") == "Daisy" 25 | stopifnot(res2) 26 | 27 | res3 = tdQuery("select c4 from padTab2 where c3='Hank'") == "Hank" 28 | stopifnot(res3) 29 | 30 | res4 = tdQuery("select c4 from padTab2 where c3='Amy'") == "Amy" 31 | stopifnot(res4) -------------------------------------------------------------------------------- /test/testNGRAM.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "test" 2 | # c1 c2 c3 3 | # ---------- ----------- ---------- 4 | # 5 cat dog 5 | # 4 robot human 6 | # 6 horse force 7 | # 3 ball bat 8 | # 1 mouse house 9 | # 2 fork spoon 10 | 11 | tdf <- td.data.frame("test") 12 | tdf["c4"] <- NGRAM(tdf["c2"], tdf["c3"], 2) 13 | as.td.data.frame(tdf, tableName="test2") 14 | 15 | #this is the resulting table, called "test2" 16 | # c1 c2 c3 c4 17 | # ---------- ----------- ---------- --------- 18 | # 5 cat dog 0 19 | # 4 robot human 0 20 | # 6 horse force 1 21 | # 3 ball bat 1 22 | # 1 mouse house 3 23 | # 2 fork spoon 0 24 | # 25 | res1 = tdQuery("select c4 from test2 where c1=5") == 0 26 | stopifnot(res1) 27 | 28 | res2 = tdQuery("select c4 from test2 where c1=4") == 0 29 | stopifnot(res2) 30 | 31 | res3 = tdQuery("select c4 from test2 where c1=6") == 1 32 | stopifnot(res3) 33 | 34 | res4 = tdQuery("select c4 from test2 where c1=3") == 1 35 | stopifnot(res4) 36 | 37 | res5 = tdQuery("select c4 from test2 where c1=1") == 3 38 | stopifnot(res5) 39 | 40 | res6 = tdQuery("select c4 from test2 where c1=2") == 0 41 | stopifnot(res6) -------------------------------------------------------------------------------- /test/testOREPLACE.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "charTab" 2 | # c1 c2 c3 c4 c5 3 | # ---------- ---- ------- --------- --------- 4 | # explore lo xx e z 5 | # interrupt ter xyz u z 6 | # disappear ar yy s z 7 | # factor ac xy c z 8 | # appreciate pp xx r z 9 | 10 | tdf <- td.data.frame("charTab") 11 | tdf["c6"] <- OREPLACE(tdf["c1"], tdf["c2"], tdf["c3"]) 12 | as.td.data.frame(tdf, tableName="charTab2") 13 | 14 | #this is the resulting table, charTab2 15 | # c1 c2 c3 c4 c5 c6 16 | # ---------- ---- ------- --------- --------- ---------- 17 | # explore lo xx e z expxxre 18 | # interrupt ter xyz u z inxyzrupt 19 | # disappear ar yy s z disappeyy 20 | # factor ac xy c z fxytor 21 | # appreciate pp xx r z axxreciate 22 | # 23 | # To verify each entry of c6: 24 | res1 = tdQuery("select c6 from charTab2 where c1='explore'") == "expxxre" 25 | stopifnot(res1) 26 | 27 | res2 = tdQuery("select c6 from charTab2 where c1='interrupt'") == "inxyzrupt" 28 | stopifnot(res2) 29 | 30 | res3 = tdQuery("select c6 from charTab2 where c1='disappear'") == "disappeyy" 31 | stopifnot(res3) 32 | 33 | res4 = tdQuery("select c6 from charTab2 where c1='factor'") == "fxytor" 34 | stopifnot(res4) 35 | 36 | res5 = tdQuery("select c6 from charTab2 where c1='appreciate'") == "axxreciate" 37 | stopifnot(res5) -------------------------------------------------------------------------------- /test/testOTRANSLATE.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "charTab" 2 | # c1 c2 c3 c4 c5 3 | # ---------- ---- ------- --------- --------- 4 | # explore lo xx e z 5 | # interrupt ter xyz u z 6 | # disappear ar yy s z 7 | # factor ac xy c z 8 | # appreciate pp xx r z 9 | 10 | tdf <- td.data.frame("charTab") 11 | tdf["c6"] <- OTRANSLATE(tdf["c1"], tdf["c4"], tdf["c5"]) 12 | as.td.data.frame(tdf, tableName="charTab2") 13 | 14 | #this is the resulting table, charTab2 15 | # 16 | # c1 c2 c3 c4 c5 c6 17 | # ---------- ---- ------- --------- --------- ---------- 18 | # explore lo xx e z zxplorz 19 | # interrupt ter xyz u z interrzpt 20 | # disappear ar yy s z dizappear 21 | # factor ac xy c z faztor 22 | # appreciate pp xx r z appzeciate 23 | 24 | # To verify each entry of c6: 25 | res1 = tdQuery("select c6 from charTab2 where c1='explore'") == "zxplorz" 26 | stopifnot(res1) 27 | 28 | res2 = tdQuery("select c6 from charTab2 where c1='interrupt'") == "interrzpt" 29 | stopifnot(res2) 30 | 31 | res3 = tdQuery("select c6 from charTab2 where c1='disappear'") == "dizappear" 32 | stopifnot(res3) 33 | 34 | res4 = tdQuery("select c6 from charTab2 where c1='factor'") == "faztor" 35 | stopifnot(res4) 36 | 37 | res5 = tdQuery("select c6 from charTab2 where c1='appreciate'") == "appzeciate" 38 | stopifnot(res5) -------------------------------------------------------------------------------- /test/testOn.R: -------------------------------------------------------------------------------- 1 | #test On() 2 | #res1 = on(target="select *", from="tab1", partition = "any", hash = "col1") == "on (select * from tab1)\npartition by any\nhash by col1" 3 | #print(res1) 4 | #stopifnot(res1) 5 | 6 | #res2 = on(target="select *", from="tab1", hash="col1", local_order="col2") == "on (select * from tab1)\nhash by col1\nlocal order by col2" 7 | #stopifnot(res2) 8 | 9 | #res3 = on(target="tab1", partition="col1") == "on tab1\npartition by col1" 10 | #print(res3) 11 | #stopifnot(res3) 12 | 13 | #res4 = on(target="tab1", dimension= " ") == "on tab1\ndimension" 14 | #stopifnot(res4) 15 | 16 | #res5 = on(target="select 1", partition="1") == "on (select 1)\npartition by 1" 17 | #print(res5) 18 | #stopifnot(res5) 19 | 20 | #res6 = on(target="select *", from="tab1", hash="col1", local_order="col1, col2") == "on (select * from tab1)\nhash by col1\nlocal order by col1, col2" 21 | #print(res6) 22 | #stopifnot(res6) 23 | 24 | #res7 = on(target="select *", from="tab1", as="test") == "on (select * from tab1)\nas test" 25 | #print(res7) 26 | #stopifnot(res7) 27 | 28 | #on1 = on(target="select p, var1, var2, var3, var4, var5", from="TestCM_Mult", local_order="p") 29 | #littleOnClause= toQuery(selectPhrase="select * from TD_SYSFNLIB.calcmatrix", ons=on1, phase="local", as="D1") 30 | #ons2 = on(target="select *", from="TD_SYSFNLIB.calcmatrix", subQuery=on1, hash="p", local_order="p") 31 | #print(ons2) -------------------------------------------------------------------------------- /test/testPOWER.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "numTab" 2 | # 3 | # c1 c2 c3 4 | # ----------- ----------- -- 5 | # 5 2 9 6 | # 6 3 9 7 | # 3 2 9 8 | # 8 3 9 9 | # 2 4 9 10 | 11 | tdf <- td.data.frame("numTab") 12 | tdf['c4'] <- POWER(tdf['c1'], tdf['c2']) 13 | as.td.data.frame(tdf, tableName="numTab2") 14 | 15 | # this is the resulting table, called "numTab2" 16 | # c1 c2 c3 c4 17 | # ----------- ----------- -- ---------------------------------------- 18 | # 5 2 9 25 19 | # 6 3 9 216 20 | # 3 2 9 9 21 | # 8 3 9 512 22 | # 2 4 9 16 23 | 24 | # To verify each entry of c4: 25 | res1 = tdQuery("select c4 from numTab2 where c1=5") == 25 26 | stopifnot(res1) 27 | 28 | res2 = tdQuery("select c4 from numTab2 where c1=6") == 216 29 | stopifnot(res2) 30 | 31 | res3 = tdQuery("select c4 from numTab2 where c1=3") == 9 32 | stopifnot(res3) 33 | 34 | res4 = tdQuery("select c4 from numTab2 where c1=8") == 512 35 | stopifnot(res4) 36 | 37 | res5 = tdQuery("select c4 from numTab2 where c1=2") == 16 38 | stopifnot(res5) -------------------------------------------------------------------------------- /test/testRPAD.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "padTab" 2 | # c1 c2 c3 3 | # --------------- --------------- --------------- 4 | # Emily Emily Emily 5 | # Daisy Daisy Daisy 6 | # Hank Hank Hank 7 | # Amy Amy Amy 8 | # 9 | # the R code is below: 10 | tdf <- td.data.frame("padTab") 11 | tdf["c4"] <- RPAD(tdf["c3"], 15, "x") 12 | as.td.data.frame(tdf, tableName="padTab2") 13 | 14 | # Below are the results of the table, when you type "select * from padTab2" 15 | # into bteq 16 | # c1 c2 c3 c4 17 | # ---------- ---------- ---------- ------------------------------------------ 18 | # Emily Emily Emily Emilyxxxxxxxxxx 19 | # Daisy Daisy Daisy Daisyxxxxxxxxxx 20 | # Hank Hank Hank Hankxxxxxxxxxxx 21 | # Amy Amy Amy Amyxxxxxxxxxxxx 22 | # 23 | res1 = tdQuery("select c4 from padTab2 where c3='Emily'") == "Emilyxxxxxxxxxx" 24 | stopifnot(res1) 25 | 26 | res2 = tdQuery("select c4 from padTab2 where c3='Daisy'") == "Daisyxxxxxxxxxx" 27 | stopifnot(res2) 28 | 29 | res3 = tdQuery("select c4 from padTab2 where c3='Hank'") == "Hankxxxxxxxxxxx" 30 | stopifnot(res3) 31 | 32 | res4 = tdQuery("select c4 from padTab2 where c3='Amy'") == "Amyxxxxxxxxxxxx" 33 | stopifnot(res4) -------------------------------------------------------------------------------- /test/testRTRIM.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "padTab" 2 | # c1 c2 c3 3 | # --------------- --------------- --------------- 4 | # Emily Emily Emily 5 | # Daisy Daisy Daisy 6 | # Hank Hank Hank 7 | # Amy Amy Amy 8 | 9 | tdf <- td.data.frame("padTab") 10 | tdf["c4"] <- RTRIM(tdf["c1"]) 11 | as.td.data.frame(tdf, tableName="padTab2") 12 | # c1 c2 c3 c4 13 | # ---------- ---------- ---------- ---------- 14 | # Emily Emily Emily Emily 15 | # Daisy Daisy Daisy Daisy 16 | # Hank Hank Hank Hank 17 | # Amy Amy Amy Amy 18 | res1 = tdQuery("select c4 from padTab2 where c3='Emily'") == "Emily" 19 | stopifnot(res1) 20 | 21 | res2 = tdQuery("select c4 from padTab2 where c3='Daisy'") == "Daisy" 22 | stopifnot(res2) 23 | 24 | res3 = tdQuery("select c4 from padTab2 where c3='Hank'") == "Hank" 25 | stopifnot(res3) 26 | 27 | res4 = tdQuery("select c4 from padTab2 where c3='Amy'") == "Amy" 28 | stopifnot(res4) -------------------------------------------------------------------------------- /test/testSIGN.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "negNums" 2 | # 3 | # c1 4 | # ----------- 5 | # 3 6 | # -11 7 | # 0 8 | # 4 9 | # -2 10 | # 555 11 | 12 | tdf <- td.data.frame("negNums") 13 | tdf["c2"] <- SIGN(tdf["c1"]) 14 | as.td.data.frame(tdf, tableName="negNums2") 15 | 16 | #this is the resulting table, called "negNums2" 17 | # c1 c2 18 | # ----------- ---------------------------------------- 19 | # 3 1 20 | # -11 -1 21 | # 0 0 22 | # 4 1 23 | # -2 -1 24 | # 555 1 25 | 26 | # To verify each entry of c2: 27 | res1 = tdQuery("select c2 from negNums2 where c1=3") ==1 28 | stopifnot(res1) 29 | 30 | res2 = tdQuery("select c2 from negNums2 where c1=-11") == -1 31 | stopifnot(res2) 32 | 33 | res3 = tdQuery("select c2 from negNums2 where c1=0") == 0 34 | stopifnot(res3) 35 | 36 | res4 = tdQuery("select c2 from negNums2 where c1=4") == 1 37 | stopifnot(res4) 38 | 39 | res5 = tdQuery("select c2 from negNums2 where c1=-2") == -1 40 | stopifnot(res5) 41 | 42 | res6 = tdQuery("select c2 from negNums2 where c1=555") == 1 43 | stopifnot(res6) -------------------------------------------------------------------------------- /test/testTO_CHAR.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "numTab" 2 | # c1 c2 c3 3 | # ----------- ----------- -- 4 | # 5 2 9 5 | # 6 3 9 6 | # 3 2 9 7 | # 8 3 9 8 | # 2 4 9 9 | 10 | tdf <- td.data.frame("numTab") 11 | tdf["c4"] <- TO_CHAR(tdf["c1"], tdf["c3"]) 12 | as.td.data.frame(tdf, tableName="numTab2") 13 | 14 | # this is the resulting table, called "numTab2" Although the values look 15 | # unchanged, the type of 'c4' is a varchar, while the type of 'c1' is an 16 | # integer. This can be verified by typing "show table numTab2" into bteq or 17 | # "tdQuery("show table numTab2")" into RStudio. 18 | # c1 c2 c3 c4 19 | # ----------- ----------- -- ------------------------------------------------ 20 | # 5 2 9 5 21 | # 6 3 9 6 22 | # 3 2 9 3 23 | # 8 3 9 8 24 | # 2 4 9 2 25 | 26 | # To verify each entry of c4: 27 | res1 = tdQuery("select c4 from numTab2 where c1=5") == '5' 28 | stopifnot(res1) 29 | 30 | res2 = tdQuery("select c4 from numTab2 where c1=6") == '6' 31 | stopifnot(res2) 32 | 33 | res3 = tdQuery("select c4 from numTab2 where c1=3") == '3' 34 | stopifnot(res3) 35 | 36 | res4 = tdQuery("select c4 from numTab2 where c1=8") == '8' 37 | stopifnot(res4) 38 | 39 | res5 = tdQuery("select c4 from numTab2 where c1=2") == '2' 40 | stopifnot(res5) -------------------------------------------------------------------------------- /test/testTO_NUMBER.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "numManip" 2 | # c1 c2 3 | # ----- ---------------------------------------- 4 | # 2 8.289 5 | # 5 13.99 6 | # 4 17.06 7 | # 3 48.1 8 | # 1 555.3 9 | # 10 | # the R code is below: 11 | tdf <- td.data.frame("numManip") 12 | tdf["c3"] <- TO_NUMBER(tdf['c1']) 13 | as.td.data.frame(tdf, tableName="numManip2") 14 | # 15 | # Below are the results of the table, when you type "select * from numManip2" 16 | # c1 c2 c3 17 | # ----- ---------------------------------------- ---------------------------- 18 | # 2 8.289 2 19 | # 5 13.99 5 20 | # 4 17.06 4 21 | # 3 48.1 3 22 | # 1 555.3 1 23 | # 24 | # To verify the data type of c3, type 'show table numManip2' into bteq: 25 | # CREATE SET TABLE ECOLE.numManip2 ,NO FALLBACK , 26 | # NO BEFORE JOURNAL, 27 | # NO AFTER JOURNAL, 28 | # CHECKSUM = DEFAULT, 29 | # DEFAULT MERGEBLOCKRATIO 30 | # ( 31 | # c1 CHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC, 32 | # c2 NUMBER, 33 | # c3 NUMBER) 34 | # PRIMARY INDEX ( c1 ); 35 | # 36 | # To verify each entry of c3: 37 | res1 = tdQuery("select c3 from numManip2 where c1='2'") == 2 38 | stopifnot(res1) 39 | 40 | res2 = tdQuery("select c3 from numManip2 where c1='5'") == 5 41 | stopifnot(res2) 42 | 43 | res3 = tdQuery("select c3 from numManip2 where c1='4'") == 4 44 | stopifnot(res3) 45 | 46 | res4 = tdQuery("select c3 from numManip2 where c1='3'") == 3 47 | stopifnot(res4) 48 | 49 | res5 = tdQuery("select c3 from numManip2 where c3='1'") == 1 50 | stopifnot(res5) -------------------------------------------------------------------------------- /test/testTRUNC.R: -------------------------------------------------------------------------------- 1 | # Below is the table used for the test, called "numManip" 2 | # c1 c2 3 | # ----- ---------------------------------------- 4 | # 2 8.289 5 | # 5 13.99 6 | # 4 17.06 7 | # 3 48.1 8 | # 1 555.3 9 | # 10 | # the R code is below: 11 | tdf <- td.data.frame("numManip") 12 | tdf["c3"] <- TRUNC(tdf["c2"], 1) 13 | as.td.data.frame(tdf, tableName="numManip2") 14 | # Below are the results of the table, when you type "select * from numManip2" 15 | # c1 c2 c3 16 | # ----- ---------------------------------------- ------------------------- 17 | # 2 8.289 8.2 18 | # 5 13.99 13.9 19 | # 4 17.06 17 20 | # 3 48.1 48.1 21 | # 1 555.3 555.3 22 | # 23 | # To verify each entry of c3: 24 | res1 = tdQuery("select c3 from numManip2 where c1='2'") == 8.2 25 | stopifnot(res1) 26 | 27 | res2 = tdQuery("select c3 from numManip2 where c1='5'") == 13.9 28 | stopifnot(res2) 29 | 30 | res3 = tdQuery("select c3 from numManip2 where c1='4'") == 17 31 | stopifnot(res3) 32 | 33 | res4 = tdQuery("select c3 from numManip2 where c1='3'") == 48.1 34 | stopifnot(res4) 35 | 36 | res5 = tdQuery("select c3 from numManip2 where c1='1'") == 555.3 37 | stopifnot(res5) -------------------------------------------------------------------------------- /test/testUtil.R: -------------------------------------------------------------------------------- 1 | #test makePartition() 2 | #res= .td.makePartition("col1, col2") == "partition by col1, col2" 3 | #print(res) 4 | #stopifnot(res) 5 | 6 | #res = .td.makePartition(partition = "any") == "partition by any" 7 | #stopifnot(res) 8 | 9 | #test makeHash() 10 | #res = .td.makeHash("col1") == "hash by col1" 11 | #stopifnot(res) 12 | 13 | #res = .td.makeHash("col1") == "nope" 14 | #stopifnot(res) 15 | 16 | #test makeOrder() 17 | #res = .td.makeOrder("col1, col2") == "order by col1, col2" 18 | #stopifnot(res) 19 | 20 | #test makeDimension() 21 | #res = .td.makeDimension() == "dimension" 22 | #stopifnot(res) 23 | 24 | #test makeLocalOrder() 25 | #res = .td.makeLocalOrder("col1") 26 | --------------------------------------------------------------------------------