Skip to content

Commit

Permalink
Removal of tbl_df from code per dplyr's new df[, 1] as a tbl_df appro…
Browse files Browse the repository at this point in the history
…ach.

Revamped vignette to fix old errors and bugs.
  • Loading branch information
trinker committed Oct 1, 2014
1 parent 9ead397 commit a65b028
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 49 deletions.
1 change: 1 addition & 0 deletions R/chaining.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,6 @@
#' @param lhs The value to be piped.
#' @param rhs A function or expression.
#' @export
#' @importFrom dplyr tbl_df
#' @rdname chain
`%>%` <- dplyr::`%>%`
3 changes: 2 additions & 1 deletion R/random_sent.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ random_data <- function(n = 10, ..., n.people = 10, ages = 7:10,
rownames(output) <- NULL

text.var <- "dialogue"
output <- dplyr::tbl_df(output)
# removed on 10/1 per tbl_df no longer returning vector for df[, 1]
# output <- dplyr::tbl_df(output)
class(output) <- unique(c("sent_split", "qdap_df", paste0("sent_split_text_var:",
text.var), class(output)))
attributes(output)[["text.var"]] <- text.var
Expand Down
2 changes: 0 additions & 2 deletions R/sentSplit.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#' \code{\link[qdap]{TOT}}
#' @keywords sentence, split, turn-of-talk
#' @export
#' @importFrom dplyr tbl_df
#' @examples
#' \dontrun{
#' ## `sentSplit` EXAMPLE:
Expand Down Expand Up @@ -132,7 +131,6 @@ function(dataframe, text.var, rm.var = NULL, endmarks = c("?", ".", "!", "|"),
if (!is.null(rm.var)) {
rm.var <- paste0("rmvars_", paste(rm.var, collapse = ":"))
}
output <- tbl_df(output)
class(output) <- unique(c("sent_split", "qdap_df",
paste0("sent_split_text_var:", text.var), rm.var, class(output)))
attributes(output)[["text.var"]] <- text.var
Expand Down
4 changes: 2 additions & 2 deletions R/tot_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ tot_plot <- function(dataframe, text.var, grouping.var = NULL, facet.vars = NULL
if (!"tot" %in% colnames(dataframe)) {
stop("supply valid tot argument")
}
tot <- TOT(dataframe[, "tot"])
tot <- TOT(dataframe[["tot"]])

} else {

Expand All @@ -96,7 +96,7 @@ tot_plot <- function(dataframe, text.var, grouping.var = NULL, facet.vars = NULL
DF[, "qdapIDqdap"] <- seq_len(nrow(DF))

## Split, order and make tot
rmout <- lapply(split(DF, DF[, facet.vars]), function(x) {
rmout <- lapply(split(DF, DF[[facet.vars]]), function(x) {
x <- x[order(x[, "qdapIDqdap"]), ]
x[, "tot"] <- seq_len(nrow(x))
x
Expand Down
8 changes: 4 additions & 4 deletions R/word_cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@
#' ## Throws multiple warning because small data set
#' library(qdapTools)
#' lapply(DATA3, function(x) {
#' word_cor(x[, "state"], id(x), qcv(computer, i, no, good), r = NULL)
#' word_cor(x[, "state"], qdapTools::id(x), qcv(computer, i, no, good), r = NULL)
#' })
#'
#' ## Find words correlated per turn of talk by person
#' ## Throws multiple warning because small data set
#' lapply(DATA3, function(x) {
#' word_cor(x[, "state"], id(x), qcv(computer, i, no, good))
#' word_cor(x[, "state"], qdapTools::id(x), qcv(computer, i, no, good))
#' })
#'
#'
Expand All @@ -93,7 +93,7 @@
#' negative = qcv(no, dumb, distrust, not, stinks),
#' literacy = qcv(computer, talking, telling)
#' )
#' y <- wfdf(DATA$state, id(DATA, prefix = TRUE))
#' y <- wfdf(DATA$state, qdapTools::id(DATA, prefix = TRUE))
#' z <- wfm_combine(y, worlis)
#'
#' out <- word_cor(t(z), word = c(names(worlis), "else.words"), r = NULL)
Expand Down Expand Up @@ -124,7 +124,7 @@ word_cor <- function(text.var, grouping.var = NULL, word, r = .7,
WFM <- t(wfm(text.var = text.var, grouping.var = grouping.var, ...))
}

WFM <- data.frame(WFM, check.names = F)
WFM <- data.frame(WFM, check.names = FALSE)
wordlen <- length(word) == 1

test1 <- word %in% colnames(WFM)
Expand Down
Binary file modified data/DATA.SPLIT.rda
Binary file not shown.
Binary file modified data/hamlet.rda
Binary file not shown.
Binary file modified inst/Rmd_vignette/data/poldat4.rds
Binary file not shown.
34 changes: 17 additions & 17 deletions inst/Rmd_vignette/qdap_vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3229,7 +3229,7 @@ termco(DATA$state, DATA$person, syns)
```

```{r echo = FALSE}
termco(DATA$state, DATA$person, syns)$rnp[, c(1:4, 9:10)]
termco(DATA[["state"]], DATA[["person"]], syns)$rnp[, c(1:4, 7:8)]
```

`r FUN("termco")` also has a plot method that plots a heat map of the `r FUN("termco")` output based on the percent usage by grouping variable. This allows for rapid visualizations of patterns and enables fast spotting of extreme values. Here are some plots from the `r HR("#rajex", "Romeo and Juliet Act 1 Example")` above.
Expand Down Expand Up @@ -4195,7 +4195,7 @@ qheat(scores(poldat), high="blue", low="yellow", grid=NULL, order.b="ave.polarit

<pre><code class="r">poldat4 <- with(rajSPLIT, polarity(dialogue, act, constrain = TRUE))

polcount <- counts(poldat4)$polarity
polcount <- na.omit(counts(poldat4)$polarity)
len <- length(polcount)

cummean <- function(x){cumsum(x)/seq_along(x)}
Expand All @@ -4205,30 +4205,30 @@ cumpolarity <- data.frame(cum_mean = cummean(polcount), Time=1:len)
## Calculate background rectangles
ends <- cumsum(rle(counts(poldat4)$act)$lengths)
starts <- c(1, head(ends + 1, -1))
rects <- data.frame(xstart = starts, xend = ends + 1,
rects <- data.frame(xstart = starts, xend = ends + 1,
Act = c("I", "II", "III", "IV", "V"))

library(ggplot2)
ggplot() + theme_bw() +
geom_rect(data = rects, aes(xmin = xstart, xmax = xend,
ymin = -Inf, ymax = Inf, fill = Act), alpha = 0.2) +
geom_rect(data = rects, aes(xmin = xstart, xmax = xend,
ymin = -Inf, ymax = Inf, fill = Act), alpha = 0.17) +
geom_smooth(data = cumpolarity, aes(y=cum_mean, x = Time)) +
geom_hline(y=mean(polcount), color="grey30", size=1, alpha=.3, linetype=2) +
annotate("text", x = mean(ends[1:2]), y = mean(polcount), color="grey30",
geom_hline(y=mean(polcount), color="grey30", size=1, alpha=.3, linetype=2) +
annotate("text", x = mean(ends[1:2]), y = mean(polcount), color="grey30",
label = "Average Polarity", vjust = .3, size=3) +
geom_line(data = cumpolarity, aes(y=cum_mean, x = Time), size=1) +
ylab("Cumulative Average Polarity") + xlab("Duration") +
scale_x_continuous(expand = c(0,0)) +
geom_text(data=rects, aes(x=(xstart + xend)/2, y=-.04,
label=paste("Act", Act)), size=3) +
geom_text(data=rects, aes(x=(xstart + xend)/2, y=-.04,
label=paste("Act", Act)), size=3) +
guides(fill=FALSE) +
scale_fill_brewer(palette="Set1")
</code></pre>

```{r, echo = FALSE, fig.width=14.5, fig.height=6, message=FALSE, warning=FALSE}
poldat4 <- readRDS("data/poldat4.rds")
polcount <- counts(poldat4)$polarity
polcount <- na.omit(counts(poldat4)$polarity)
len <- length(polcount)
cummean <- function(x){cumsum(x)/seq_along(x)}
Expand All @@ -4238,22 +4238,22 @@ cumpolarity <- data.frame(cum_mean = cummean(polcount), Time=1:len)
## Calculate background rectangles
ends <- cumsum(rle(counts(poldat4)$act)$lengths)
starts <- c(1, head(ends + 1, -1))
rects <- data.frame(xstart = starts, xend = ends + 1,
rects <- data.frame(xstart = starts, xend = ends + 1,
Act = c("I", "II", "III", "IV", "V"))
library(ggplot2)
ggplot() + theme_bw() +
geom_rect(data = rects, aes(xmin = xstart, xmax = xend,
ymin = -Inf, ymax = Inf, fill = Act), alpha = 0.2) +
geom_rect(data = rects, aes(xmin = xstart, xmax = xend,
ymin = -Inf, ymax = Inf, fill = Act), alpha = 0.17) +
geom_smooth(data = cumpolarity, aes(y=cum_mean, x = Time)) +
geom_hline(y=mean(polcount), color="grey30", size=1, alpha=.3, linetype=2) +
annotate("text", x = mean(ends[1:2]), y = mean(polcount), color="grey30",
geom_hline(y=mean(polcount), color="grey30", size=1, alpha=.3, linetype=2) +
ggplot2::annotate("text", x = mean(ends[1:2]), y = mean(polcount), color="grey30",
label = "Average Polarity", vjust = .3, size=3) +
geom_line(data = cumpolarity, aes(y=cum_mean, x = Time), size=1) +
ylab("Cumulative Average Polarity") + xlab("Duration") +
scale_x_continuous(expand = c(0,0)) +
geom_text(data=rects, aes(x=(xstart + xend)/2, y=-.04,
label=paste("Act", Act)), size=3) +
geom_text(data=rects, aes(x=(xstart + xend)/2, y=-.04,
label=paste("Act", Act)), size=3) +
guides(fill=FALSE) +
scale_fill_brewer(palette="Set1")
```
Expand Down
Loading

0 comments on commit a65b028

Please sign in to comment.