Skip to content

Commit

Permalink
address unbound variable in summaries functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bvreede committed Oct 6, 2023
1 parent 1d85b14 commit 60cdf81
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions R/summaries.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,57 @@ report_summaries <- function(data, lang, allsources){

if(allsources) {
print(knitr::kable(bysource |>
dplyr::select(-start,-finish,-talktime,-totaltime)))
dplyr::select(-"start",
-"finish",
-"talktime",
-"totaltime")))
} else {
if(nsources > 10) {
cat("\n")
cat("Showing only the first 10 sources; use `allsources=T` to show all")
}
print(knitr::kable(bysource |>
dplyr::select(-start,-finish,-talktime,-totaltime) |>
dplyr::select(-"start",
-"finish",
-"talktime",
-"totaltime") |>
dplyr::slice(1:10)))
}
}



summarize_language_data <- function(data, lang){
if(!"translation" %in% colnames(data)){
data$translation <- NA
}

data |>
dplyr::filter(language == lang) |>
dplyr::group_by(source) |>
dplyr::mutate(translation = ifelse(is.na(translation),0,1)) |>
dplyr::summarize(start=min.na(begin),finish=max.na(end),
turns=dplyr::n_distinct(uid),
translated=round(sum(translation)/turns,2),
words=sum(nwords,na.rm=T),
people=dplyr::n_distinct(participant),
talktime = sum(duration),
totaltime = finish - start,
talkprop = round(talktime / totaltime,1),
minutes = round((totaltime/1000 / 60),1),
hours = round((totaltime/1000) / 3600,2))
dplyr::filter(.data$language == lang) |>
dplyr::group_by(.data$source) |>
dplyr::mutate(translation = ifelse(is.na(.data$translation),0,1)) |>
dplyr::summarize(start=min.na(.data$begin),finish=max.na(.data$end),
turns=dplyr::n_distinct(.data$uid),
translated=round(sum(.data$translation)/.data$turns,2),
words=sum(.data$nwords,na.rm=T),
people=dplyr::n_distinct(.data$participant),
talktime = sum(.data$duration),
totaltime = .data$finish - .data$start,
talkprop = round(.data$talktime / .data$totaltime,1),
minutes = round((.data$totaltime/1000 / 60),1),
hours = round((.data$totaltime/1000) / 3600,2))
}


summarize_source_data <- function(data, lang){
data |>
summarize_language_data(lang=lang) |> #TODO this uses another function?
dplyr::summarize(turns = sum(turns),
translated=round(mean.na(translated),2),
words = sum(words),
turnduration=round(mean.na(sum(talktime)/turns)),
talkprop = round(mean.na(talkprop),2),
dplyr::summarize(turns = sum(.data$turns),
translated=round(mean.na(.data$translated),2),
words = sum(.data$words),
turnduration=round(mean.na(sum(.data$talktime)/.data$turns)),
talkprop = round(mean.na(.data$talkprop),2),
people = dplyr::n_distinct(data$participant),
hours = round(sum(hours),2),
turns_per_h = round(turns/hours)) |>
dplyr::arrange(desc(hours))
hours = round(sum(.data$hours),2),
turns_per_h = round(.data$turns/.data$hours)) |>
dplyr::arrange(desc(.data$hours))
}

0 comments on commit 60cdf81

Please sign in to comment.