Skip to content

Commit

Permalink
Use udecode instead of parse/eval
Browse files Browse the repository at this point in the history
  • Loading branch information
seancarmody committed Jul 21, 2013
1 parent b902dfd commit 1e59563
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Expand Up @@ -25,3 +25,5 @@ Collate:
'help.R'
'ggram.R'
'ngramw.R'
'themes.R'

This comment has been minimized.

Copy link
@briatte

briatte Jul 22, 2013

Contributor

I think this is what is causing the package install to fail from GitHub, because the file does not exist.

'udecode.R'
4 changes: 3 additions & 1 deletion R/ggram.R
Expand Up @@ -44,6 +44,7 @@
#'
#' # Setting the legend placement on a long query and using the Google theme.
#' # Example taken from a post by Ben Zimmer at Language Log.
#' require(ggplot2)
#' p <- c("(The United States is + The United States has) / The United States",
#' "(The United States are + The United States have) / The United States")
#' ggram(p, year_start = 1800, google_theme = TRUE) +
Expand Down Expand Up @@ -73,7 +74,8 @@ ggram <- function(phrases, ignore_case=FALSE, geom="line", ignore.case=ignore_ca
}
else if (labs & google_theme) {
# Google Ngram palette.
palette = c("#264EC0", "#D22310", "#FC8608", "#168713", "#850086", "#1086B9", "#D22B63", "#559D05", "#A71B23", "#21436F", "#852D86", "#219B86")
palette = c("#264EC0", "#D22310", "#FC8608", "#168713", "#850086", "#1086B9",
"#D22B63", "#559D05", "#A71B23", "#21436F", "#852D86", "#219B86")
p = p +
scale_colour_manual("", values = palette, labels = phrases) +
scale_fill_manual("", values = palette, labels = phrases) +
Expand Down
4 changes: 1 addition & 3 deletions R/ngram.R
Expand Up @@ -127,9 +127,7 @@ ngram_parse <- function(html){
cols <- lapply(strsplit(grep("addColumn", html, value=TRUE), ","), getElement, 2)

cols <- gsub(".*'(.*)'.*", "\\1", cols)
# Clean up Unicode encoding. See discussion here:
# http://stackoverflow.com/questions/17761858/converting-a-u-escaped-unicode-string-to-ascii
cols <- sapply(cols, function(x) eval(parse(text=paste0("'", x, "'"))))
cols <- sapply(cols, udecode)

html <- paste(html[-(1:grep("data.addRows\\(", html))], collapse='')
html <- gsub("\\).*", "", html)
Expand Down
1 change: 1 addition & 0 deletions man/ggram.Rd
Expand Up @@ -63,6 +63,7 @@ ggram(c("cancer", "smoking", "tobacco"),

# Setting the legend placement on a long query and using the Google theme.
# Example taken from a post by Ben Zimmer at Language Log.
require(ggplot2)
p <- c("(The United States is + The United States has) / The United States",
"(The United States are + The United States have) / The United States")
ggram(p, year_start = 1800, google_theme = TRUE) +
Expand Down

1 comment on commit 1e59563

@seancarmody
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All sorted now, I hope.

Please sign in to comment.