Skip to content

Commit

Permalink
Removed generic function for tally() so that it doesn't conflict with…
Browse files Browse the repository at this point in the history
… dplyr::tally().
  • Loading branch information
ncondits3 committed Oct 2, 2023
1 parent cef9599 commit 8c2271f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: humdrumR
Title: humdrumR
Version: 0.7.0.0
Version: 0.7.0.1
Authors@R: c(person("Nathaniel", "Condit-Schultz", email = "[email protected]", role = c("aut", "cre")),
person("Claire", "Arthur", email = "[email protected]", role = "aut"))
Description: This package is a toolkit for the visualization, manipulation, and analysis of data encoded in the Humdrum syntax (<http://www.humdrum.org).
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ importFrom(dplyr,reframe)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(dplyr,summarize)
importFrom(dplyr,tally)
importFrom(dplyr,ungroup)
importFrom(ggplot2,aes)
importFrom(ggplot2,geom_bar)
Expand Down
50 changes: 30 additions & 20 deletions R/Analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,26 @@ setClass('humdrum.table', contains = 'table')
#'
#' cbind(genericTable, complexTable)
#'
#' @name tally
#' @export
tally <- function(..., na.rm, exclude) UseMethod('tally')
tally.humdrumR <- function(x, ..., sort = FALSE, na.rm = FALSE, exclude = NULL) {
quos <- rlang::enquos(...)

if (length(quos)) {
quo <- rlang::quo(with(x, tally(!!!quos, na.rm = !!na.rm, exclude = !!exclude)))
rlang::eval_tidy(quo)


} else {
fields <- pullFields(x, union(selectedFields(x), getGroupingFields(x)))

do.call('tally', c(as.list(fields), list(na.rm = na.rm, exclude = exclude)))
}
}


#' @export
tally.default <- function(...,
tally.default <- function(..., sort = FALSE,
na.rm = FALSE,
exclude = NULL) {

Expand All @@ -85,31 +101,25 @@ tally.default <- function(...,
# dimnames(tab) <- lapply(dimnames(tab), \(dn) ifelse(is.na(dn), 'NA', dn))
names(dimnames(tab)) <- dimnames


new('humdrum.table', tab)


}

#' @export
tally.humdrumR <- function(x, ..., na.rm = FALSE, exclude = NULL) {
quos <- rlang::enquos(...)

if (length(quos)) {
quo <- rlang::quo(with(x, tally(!!!quos, na.rm = !!na.rm, exclude = !!exclude)))
rlang::eval_tidy(quo)


} else {
fields <- pullFields(x, union(selectedFields(x), getGroupingFields(x)))
if (sort) {
if (length(dimnames) > 1) {
for (i in seq_along(dimnames)) {
reorder <- order(apply(tab, i, sum), decreasing = TRUE)
tab <- apply(tab, seq_along(dimnames)[-i], '[', i = reorder)
}
} else {
tab <- sort(tab, decreasing = TRUE)
}

do.call('tally', c(as.list(fields), list(na.rm = na.rm, exclude = exclude)))
class(tab) <- 'table'
}

new('humdrum.table', tab)


}



#' @rdname tally
#' @export
Expand Down
4 changes: 2 additions & 2 deletions R/humdrumR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
#' @importFrom numbers primeFactors
#' @importFrom data.table data.table rbindlist setorder setindex set setorderv setcolorder copy as.data.table is.data.table frank CJ setnames setkey
#' @importFrom scales ContinuousRange
#' @importFrom dplyr summarise select filter mutate pull reframe group_by ungroup summarize
#' @importFrom dplyr summarise select filter mutate pull reframe group_by ungroup summarize tally
#' @importFrom tidyselect eval_select
#' @importFrom tidyr pivot_wider pivot_longer
#' @importFrom ggplot2 ggplot update_geom_defaults scale_color_gradientn scale_type aes geom_bar geom_point
#' @export summarise select filter mutate pull reframe group_by ungroup summarize
#' @export summarise select filter mutate pull reframe group_by ungroup summarize tally
NULL


Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/tally.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c2271f

Please sign in to comment.