-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from dmurdoch/deparse
Always deparse to one line. Avoid deparsing in All().
- Loading branch information
Showing
4 changed files
with
52 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,50 @@ | ||
All <- function(df, numeric=TRUE, character=FALSE, logical=FALSE, factor=FALSE, | ||
complex=FALSE, raw=FALSE, other=FALSE, | ||
texify=getOption("tables.texify", FALSE)) { | ||
|
||
if (is.character(numeric)) numeric <- get(numeric, mode="function", | ||
envir=parent.frame()) | ||
if (is.character(character)) character <- get(character, mode="function", | ||
envir=parent.frame()) | ||
if (is.character(logical)) logical <- get(logical, mode="function", | ||
envir=parent.frame()) | ||
if (is.character(factor)) factor <- get(factor, mode="function", | ||
envir=parent.frame()) | ||
if (is.character(complex)) complex <- get(complex, mode="function", | ||
envir=parent.frame()) | ||
if (is.character(complex)) complex <- get(complex, mode="function", | ||
envir=parent.frame()) | ||
if (is.character(raw)) raw <- get(raw, mode="function", | ||
envir=parent.frame()) | ||
if (is.character(other)) other <- get(other, mode="function", | ||
envir=parent.frame()) | ||
|
||
All <- function(df, | ||
numeric = TRUE, | ||
character = FALSE, | ||
logical = FALSE, | ||
factor = FALSE, | ||
complex = FALSE, | ||
raw = FALSE, | ||
other = FALSE, | ||
texify = getOption("tables.texify", FALSE)) { | ||
names <- colnames(df) | ||
if (texify) | ||
names <- Hmisc::latexTranslate(names) | ||
names <- Hmisc::latexTranslate(names) | ||
|
||
f <- NULL | ||
for (i in seq_along(names)) { | ||
value <- df[[i]] | ||
if (is.numeric(value)) { | ||
if (is.function(numeric)) | ||
value <- numeric(value) | ||
else if (!isTRUE(numeric)) | ||
next | ||
} else if (is.character(value)) { | ||
if (is.function(character)) | ||
value <- character(value) | ||
else if (!isTRUE(character)) | ||
next | ||
} else if (is.logical(value)) { | ||
if (is.function(logical)) | ||
value <- logical(value) | ||
else if (!isTRUE(logical)) | ||
next | ||
} else if (is.factor(value)) { | ||
if (is.function(factor)) | ||
value <- factor(value) | ||
else if (!isTRUE(factor)) | ||
next | ||
} else if (is.complex(value)) { | ||
if (is.function(complex)) | ||
value <- complex(value) | ||
else if (!isTRUE(complex)) | ||
next | ||
} else if (is.raw(value)) { | ||
if (is.function(raw)) | ||
value <- raw(value) | ||
else if (!isTRUE(raw)) | ||
next | ||
} else { | ||
if (is.function(other)) | ||
value <- other(value) | ||
else if (!isTRUE(other)) | ||
next | ||
} | ||
|
||
f1 <- call("*", call("Heading", as.name(names[i])), | ||
value) | ||
if (is.null(f)) | ||
f <- f1 | ||
else | ||
f <- call("+", f, f1) | ||
value <- df[[i]] | ||
if (is.numeric(value)) | ||
sel <- numeric | ||
else if (is.character(value)) | ||
sel <- character | ||
else if (is.logical(value)) | ||
sel <- logical | ||
else if (is.factor(value)) | ||
sel <- factor | ||
else if (is.complex(value)) | ||
sel <- complex | ||
else if (is.raw(value)) | ||
sel <- raw | ||
else | ||
sel <- other | ||
|
||
if (is.character(sel)) | ||
sel <- get(sel, mode = "function", envir = parent.frame()) | ||
|
||
if (is.function(sel)) | ||
value <- sel(value) | ||
else if (isTRUE(sel)) | ||
value <- call("[[", substitute(df), i) | ||
else | ||
next | ||
|
||
f1 <- call("*", call("Heading", as.name(names[i])), | ||
value) | ||
if (is.null(f)) | ||
f <- f1 | ||
else | ||
f <- call("+", f, f1) | ||
} | ||
f | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# base::deparse might return more than one line; this | ||
# replaces it with a function that chops the results | ||
|
||
deparse <- function(expr, width.cutoff = 500L, nlines = 1L, ...) { | ||
base::deparse(expr, width.cutoff = width.cutoff, nlines = nlines, ...) | ||
} |