Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
Better replacement of string needs ()
Browse files Browse the repository at this point in the history
  • Loading branch information
Qian, Hai committed Apr 18, 2014
1 parent e5b919c commit a61483d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: PivotalR
Type: Package
Title: R front-end to PostgreSQL and Pivotal (Greenplum) database,
wrapper for MADlib
Version: 0.1.15.36
Version: 0.1.15.38
Date: 2014-03-10
Author: Predictive Analytics Team at Pivotal Inc. <user@madlib.net>,
with contributions from Data Scientist Team at Pivotal Inc.
Expand Down
15 changes: 8 additions & 7 deletions R/utility-generic.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ arraydb.to.arrayr <- function (str, type = "double", n = 1)

## ## grouping column do not use factor
f2.labels <- .gsub("I\\((.*)\\)", "(\\1)", f2.labels, perl = T)
f2.labels <- .gsub("as\\.factor\\((.*)\\)", "\\1", f2.labels, perl = T)
f2.labels <- .gsub("factor\\((.*)\\)", "\\1", f2.labels, perl = T)
f2.labels <- .gsub("as\\.factor\\((.*)\\)", "(\\1)", f2.labels, perl = T)
f2.labels <- .gsub("factor\\((.*)\\)", "(\\1)", f2.labels, perl = T)

grp.expr <- f2.labels
for (i in seq_len(length(f2.labels))) {
Expand Down Expand Up @@ -250,7 +250,7 @@ arraydb.to.arrayr <- function (str, type = "double", n = 1)
## f.labels <- gsub("`([^`]*)(\\[\\d+\\])`", "\"\\1\"\\2", f.labels)
right.hand <- paste(f.labels, collapse = "+")
if (refresh) { # second pass
right.hand <- .gsub("as\\.factor\\((((?!as\\.factor).)*)\\)", "\\1", right.hand, perl = T)
right.hand <- .gsub("as\\.factor\\((((?!as\\.factor).)*)\\)", "(\\1)", right.hand, perl = T)

if (sum(data@.is.factor) > 0) {
distinct <- list()
Expand Down Expand Up @@ -295,8 +295,9 @@ arraydb.to.arrayr <- function (str, type = "double", n = 1)
elm <- .regmatches(right.hand,
gregexpr("as\\.factor\\s*\\([^\\(\\)]+\\)",
right.hand, perl=T))[[1]]
col <- .strip(.gsub("as\\.factor\\s*\\(([^\\(\\)]+)\\)", "\\1", elm,
col <- .strip(.gsub("as\\.factor\\s*\\(([^\\(\\)]+)\\)", "(\\1)", elm,
perl = T))
col <- gsub("^\\((.*)\\)$", "\\1", col)
if (!all(col %in% names(data)))
stop("At least one of the variables cannot be set to be a factor ",
"because either it does not exist in the data table ",
Expand All @@ -309,7 +310,7 @@ arraydb.to.arrayr <- function (str, type = "double", n = 1)
## factors added by formula
for (cl in col) data[[cl]] <- as.factor(data[[cl]])

right.hand <- .gsub("as\\.factor\\((((?!as\\.factor).)*)\\)", "\\1", right.hand, perl = T)
right.hand <- .gsub("as\\.factor\\((((?!as\\.factor).)*)\\)", "(\\1)", right.hand, perl = T)
## right.hand <- gsub("factor\\((((?!factor).)*)\\)", "\\1", right.hand, perl = T)
}

Expand All @@ -329,8 +330,8 @@ arraydb.to.arrayr <- function (str, type = "double", n = 1)
## dependent variable
## factor does not play a role in dependent variable
dep.var <- .gsub("I\\((.*)\\)", "(\\1)", rownames(f.factors)[1], perl = T)
dep.var <- .gsub("as\\.factor\\((.*)\\)", "\\1", dep.var, perl = T)
dep.var <- .gsub("factor\\((.*)\\)", "\\1", dep.var, perl = T)
dep.var <- .gsub("as\\.factor\\((.*)\\)", "(\\1)", dep.var, perl = T)
dep.var <- .gsub("factor\\((.*)\\)", "(\\1)", dep.var, perl = T)
## dep.var <- .replace.with.quotes(dep.var, data@.col.name)
origin.dep <- dep.var

Expand Down

0 comments on commit a61483d

Please sign in to comment.