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

Commit

Permalink
Bug fix: correctly handle column name which is a substring of another
Browse files Browse the repository at this point in the history
longer column name
  • Loading branch information
Qian, Hai committed Apr 16, 2014
1 parent bd37382 commit 7d3f31c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 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.27
Version: 0.1.15.29
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
21 changes: 12 additions & 9 deletions R/margins.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ Vars <- function(model)
## Add `\"\"` quotes to vars using model.vars
.add.quotes <- function(vars, model.vars)
{
as.vector(sapply(vars,
function(v) {
for (var in model.vars)
v <- gsub(var, paste("`\"", var, "\"`", sep = ""), v)
v <- gsub("([^`]|^)\"([^\\[\\]]*)\"\\[(\\d+)\\]([^`]|$)",
"(`\"\\2\"[\\3]`)", v)
v
}))
no.conflict.names <- sapply(seq_along(model.vars), function(i) .unique.string())
parse.var <- function (v) {
for (i in order(nchar(model.vars), decreasing = TRUE))
v <- gsub(model.vars[i], paste("`\"", no.conflict.names[i], "\"`", sep = ""),
v, perl = TRUE)
for (i in seq_along(model.vars))
v <- gsub(no.conflict.names[i], model.vars[i], v, perl = TRUE)
v <- gsub("([^`]|^)\"([^\\[\\]]*)\"\\[(\\d+)\\]([^`]|$)",
"(`\"\\2\"[\\3]`)", v, perl = TRUE)
v
}
as.vector(sapply(vars, parse.var))
}

## ----------------------------------------------------------------------
Expand Down Expand Up @@ -204,7 +208,6 @@ Vars <- function(model)
## ------- Add quotes -------
mvars <- Vars(model)
model.vars <- .add.quotes(gsub("`", "", model.vars), mvars)

model.vars <- lapply(model.vars, function(x)
eval(parse(text=paste("quote(", x, ")", sep = ""))))

Expand Down

0 comments on commit 7d3f31c

Please sign in to comment.