Skip to content

Commit

Permalink
replace tibble_pole with tibble using .rows argument
Browse files Browse the repository at this point in the history
  • Loading branch information
corybrunson committed Oct 10, 2024
1 parent cd41a6b commit 6724b0f
Show file tree
Hide file tree
Showing 30 changed files with 395 additions and 160 deletions.
6 changes: 3 additions & 3 deletions R/dplyr-verbs.r
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ cbind_factor <- function(.data, ..., .matrix, elements = "all") {
elts_rows <- ann_fac$.element == elements
if (! any(elts_rows)) {
warning("No ", elements, " elements found.")
tibble_pole(nrow = nrow(ann_fac))
tibble(.rows = nrow(ann_fac))
} else {
n_above <- min(which(elts_rows)) - 1L
n_below <- min(which(rev(elts_rows))) - 1L
tbl_above <- if (n_above > 1L) tibble_pole(nrow = n_above)
tbl_below <- if (n_below > 1L) tibble_pole(nrow = n_below)
tbl_above <- if (n_above > 1L) tibble(.rows = n_above)
tbl_below <- if (n_below > 1L) tibble(.rows = n_below)
bind_rows(tbl_above, ..., tbl_below)
}
}
Expand Down
8 changes: 4 additions & 4 deletions R/methods-base-eigen.r
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ recover_conference.eigen <- function(x) {

#' @rdname methods-eigen
#' @export
recover_aug_rows.eigen_ord <- function(x) tibble_pole(nrow(x[["vectors"]]))
recover_aug_rows.eigen_ord <- function(x) tibble(.rows = nrow(x[["vectors"]]))

#' @rdname methods-eigen
#' @export
recover_aug_cols.eigen_ord <- function(x) tibble_pole(nrow(x[["vectors"]]))
recover_aug_cols.eigen_ord <- function(x) tibble(.rows = nrow(x[["vectors"]]))

#' @rdname methods-eigen
#' @export
Expand Down Expand Up @@ -101,7 +101,7 @@ recover_conference.eigen_ord <- recover_conference.eigen
recover_aug_rows.eigen_ord <- function(x) {
name <- rownames(x[["vectors"]])
res <- if (is.null(name)) {
tibble_pole(nrow(x[["vectors"]]))
tibble(.rows = nrow(x[["vectors"]]))
} else {
tibble(name = name)
}
Expand All @@ -113,7 +113,7 @@ recover_aug_rows.eigen_ord <- function(x) {
recover_aug_cols.eigen_ord <- function(x) {
name <- rownames(x[["vectors"]])
res <- if (is.null(name)) {
tibble_pole(nrow(x[["vectors"]]))
tibble(.rows = nrow(x[["vectors"]]))
} else {
tibble(name = name)
}
Expand Down
4 changes: 2 additions & 2 deletions R/methods-base-svd.r
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ recover_conference.svd_ord <- function(x) {
recover_aug_rows.svd_ord <- function(x) {
name <- rownames(x[["u"]])
if (is.null(name)) {
tibble_pole(nrow(x[["u"]]))
tibble(.rows = nrow(x[["u"]]))
} else {
tibble(name = name)
}
Expand All @@ -55,7 +55,7 @@ recover_aug_rows.svd_ord <- function(x) {
recover_aug_cols.svd_ord <- function(x) {
name <- rownames(x[["v"]])
if (is.null(name)) {
tibble_pole(nrow(x[["v"]]))
tibble(.rows = nrow(x[["v"]]))
} else {
tibble(name = name)
}
Expand Down
4 changes: 2 additions & 2 deletions R/methods-mass-correspondence.r
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ recover_coord.correspondence <- function(x) {
recover_aug_rows.correspondence <- function(x) {
name <- rownames(as.matrix(x$rscore))
if (is.null(name)) {
tibble_pole(nrow(as.matrix(x$rscore)))
tibble(.rows = nrow(as.matrix(x$rscore)))
} else {
tibble(name = name)
}
Expand All @@ -66,7 +66,7 @@ recover_aug_rows.correspondence <- function(x) {
recover_aug_cols.correspondence <- function(x) {
name <- rownames(as.matrix(x$cscore))
if (is.null(name)) {
tibble_pole(nrow(as.matrix(x$cscore)))
tibble(.rows = nrow(as.matrix(x$cscore)))
} else {
tibble(name = name)
}
Expand Down
6 changes: 3 additions & 3 deletions R/methods-mass-lda.r
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ recover_conference.lda_ord <- recover_conference.lda
#' @export
recover_aug_rows.lda <- function(x) {
res <- if (is.null(rownames(x$means))) {
tibble_pole(nrow(x$means))
tibble(.rows = nrow(x$means))
} else {
tibble(name = rownames(x$means))
}
Expand Down Expand Up @@ -124,7 +124,7 @@ recover_aug_rows.lda <- function(x) {
#' @export
recover_aug_rows.lda_ord <- function(x) {
res <- if (is.null(rownames(x$means))) {
tibble_pole(nrow(x$means))
tibble(.rows = nrow(x$means))
} else {
tibble(name = rownames(x$means))
}
Expand Down Expand Up @@ -170,7 +170,7 @@ recover_aug_rows.lda_ord <- function(x) {
recover_aug_cols.lda <- function(x) {
name <- rownames(x$scaling)
res <- if (is.null(name)) {
tibble_pole(nrow(x$scaling))
tibble(.rows = nrow(x$scaling))
} else {
tibble(name = name)
}
Expand Down
6 changes: 3 additions & 3 deletions R/methods-mass-mca.r
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ recover_supp_rows.mca <- function(x) {
recover_aug_rows.mca <- function(x) {
name <- rownames(x$fs)
res <- if (is.null(name)) {
tibble_pole(nrow(x$fs))
tibble(.rows = nrow(x$fs))
} else {
tibble(name = name)
}

# row coordinates as supplementary points
name <- rownames(x$rs)
res_sup <- if (is.null(name)) {
tibble_pole(nrow(x$rs))
tibble(.rows = nrow(x$rs))
} else {
tibble(name = name)
}
Expand All @@ -88,7 +88,7 @@ recover_aug_cols.mca <- function(x) {
name <- rownames(x$cs)
# introduce `.factor` and `.level` according to `abbrev`
if (is.null(name)) {
tibble_pole(nrow(x$cs))
tibble(.rows = nrow(x$cs))
} else if (is.null(attr(rownames(x$cs), "names"))) {
# only add `.factor` and `.level` if names are unambiguous
level_ambig <- any(grepl("\\..*\\.", rownames(x$cs)))
Expand Down
4 changes: 2 additions & 2 deletions R/methods-ordr-lra.r
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ recover_conference.lra <- function(x) {
recover_aug_rows.lra <- function(x) {
name <- rownames(x[["row.coords"]])
res <- if (is.null(name)) {
tibble_pole(nrow(x[["row.coords"]]))
tibble(.rows = nrow(x[["row.coords"]]))
} else {
tibble(name = name)
}
Expand All @@ -63,7 +63,7 @@ recover_aug_rows.lra <- function(x) {
recover_aug_cols.lra <- function(x) {
name <- rownames(x[["column.coords"]])
res <- if (is.null(name)) {
tibble_pole(nrow(x[["column.coords"]]))
tibble(.rows = nrow(x[["column.coords"]]))
} else {
tibble(name = name)
}
Expand Down
12 changes: 6 additions & 6 deletions R/methods-stats-cancor.r
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ recover_supp_cols.cancor_ord <- function(x) {
recover_aug_rows.cancor_ord <- function(x) {
name <- rownames(x$xcoef)
res <- if (is.null(name)) {
tibble_pole(nrow(x$xcoef))
tibble(.rows = nrow(x$xcoef))
} else {
tibble(name = name)
}
Expand All @@ -99,7 +99,7 @@ recover_aug_rows.cancor_ord <- function(x) {
res_sup <- NULL
if (! is.null(x$xscores)) {
res_sup_elt <- if (is.null(rownames(x$xscores))) {
tibble_pole(nrow(x$xscores))
tibble(.rows = nrow(x$xscores))
} else {
tibble(name = rownames(x$xscores))
}
Expand All @@ -108,7 +108,7 @@ recover_aug_rows.cancor_ord <- function(x) {
}
if (! is.null(x$xstructure)) {
res_sup_elt <- if (is.null(rownames(x$xstructure))) {
tibble_pole(nrow(x$xstructure))
tibble(.rows = nrow(x$xstructure))
} else {
tibble(name = rownames(x$xstructure))
}
Expand All @@ -125,7 +125,7 @@ recover_aug_rows.cancor_ord <- function(x) {
recover_aug_cols.cancor_ord <- function(x) {
name <- rownames(x$ycoef)
res <- if (is.null(name)) {
tibble_pole(nrow(x$ycoef))
tibble(.rows = nrow(x$ycoef))
} else {
tibble(name = name)
}
Expand All @@ -134,7 +134,7 @@ recover_aug_cols.cancor_ord <- function(x) {
res_sup <- NULL
if (! is.null(x$xscores)) {
res_sup_elt <- if (is.null(rownames(x$yscores))) {
tibble_pole(nrow(x$yscores))
tibble(.rows = nrow(x$yscores))
} else {
tibble(name = rownames(x$yscores))
}
Expand All @@ -143,7 +143,7 @@ recover_aug_cols.cancor_ord <- function(x) {
}
if (! is.null(x$ystructure)) {
res_sup_elt <- if (is.null(rownames(x$ystructure))) {
tibble_pole(nrow(x$ystructure))
tibble(.rows = nrow(x$ystructure))
} else {
tibble(name = rownames(x$ystructure))
}
Expand Down
4 changes: 2 additions & 2 deletions R/methods-stats-cmds.r
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ recover_conference.cmds_ord <- function(x) {
recover_aug_rows.cmds_ord <- function(x) {
name <- rownames(x$points)
res <- if (is.null(name)) {
tibble_pole(nrow(x$x))
tibble(.rows = nrow(x$x))
} else {
tibble(name = name)
}
Expand All @@ -68,7 +68,7 @@ recover_aug_rows.cmds_ord <- function(x) {
recover_aug_cols.cmds_ord <- function(x) {
name <- rownames(x$points)
res <- if (is.null(name)) {
tibble_pole(ncol(x$x))
tibble(.rows = ncol(x$x))
} else {
tibble(name = name)
}
Expand Down
6 changes: 3 additions & 3 deletions R/methods-stats-factanal.r
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ recover_supp_rows.factanal <- function(x) {
recover_aug_rows.factanal <- function(x) {
name <- rownames(x[["loadings"]])
res <- if (is.null(name)) {
tibble_pole(nrow(x[["loadings"]]))
tibble(.rows = nrow(x[["loadings"]]))
} else {
tibble(name = name)
}
if (is.null(x[["scores"]])) return(res)

# factor scores as supplementary points
res_sup <- if (is.null(rownames(x[["scores"]]))) {
tibble_pole(x[["n.obs"]])
tibble(.rows = x[["n.obs"]])
} else {
tibble(name = rownames(x[["scores"]]))
}
Expand All @@ -90,7 +90,7 @@ recover_aug_rows.factanal <- function(x) {
recover_aug_cols.factanal <- function(x) {
name <- rownames(x[["loadings"]])
res <- if (is.null(name)) {
tibble_pole(nrow(x[["loadings"]]))
tibble(.rows = nrow(x[["loadings"]]))
} else {
tibble(name = name)
}
Expand Down
4 changes: 2 additions & 2 deletions R/methods-stats-kmeans.r
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ recover_coord.kmeans <- function(x) {
recover_aug_rows.kmeans <- function(x) {
name <- names(x$cluster)
res <- if (is.null(name)) {
tibble_pole(length(x$cluster))
tibble(.rows = length(x$cluster))
} else {
tibble(name = name)
}
Expand All @@ -55,7 +55,7 @@ recover_aug_rows.kmeans <- function(x) {
recover_aug_cols.kmeans <- function(x) {
name <- colnames(x$centers)
res <- if (is.null(name)) {
tibble_pole(ncol(x$centers))
tibble(.rows = ncol(x$centers))
} else {
tibble(name = name)
}
Expand Down
4 changes: 2 additions & 2 deletions R/methods-stats-prcomp.r
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ recover_conference.prcomp <- function(x) {
recover_aug_rows.prcomp <- function(x) {
name <- rownames(x[["x"]])
if (is.null(name)) {
tibble_pole(nrow(x[["x"]]))
tibble(.rows = nrow(x[["x"]]))
} else {
tibble(name = name)
}
Expand All @@ -64,7 +64,7 @@ recover_aug_rows.prcomp <- function(x) {
recover_aug_cols.prcomp <- function(x) {
name <- rownames(x[["rotation"]])
res <- if (is.null(name)) {
tibble_pole(nrow(x[["rotation"]]))
tibble(.rows = nrow(x[["rotation"]]))
} else {
tibble(name = name)
}
Expand Down
6 changes: 3 additions & 3 deletions R/methods-stats-princomp.r
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ recover_supp_rows.princomp <- function(x) {
#' @rdname methods-princomp
#' @export
recover_aug_rows.princomp <- function(x) {
res <- tibble_pole(nrow = 0L)
res <- tibble(.rows = 0L)

# scores as supplementary points
name <- rownames(x$scores)
res_sup <- if (is.null(name)) {
tibble_pole(nrow = nrow(x$scores))
tibble(.rows = nrow(x$scores))
} else {
tibble(name = name)
}
Expand All @@ -89,7 +89,7 @@ recover_aug_rows.princomp <- function(x) {
recover_aug_cols.princomp <- function(x) {
name <- rownames(x[["loadings"]])
res <- if (is.null(name)) {
tibble_pole(nrow(x[["loadings"]]))
tibble(.rows = nrow(x[["loadings"]]))
} else {
tibble(name = name)
}
Expand Down
4 changes: 2 additions & 2 deletions R/ord-annotation.r
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ set_annotation_factor <- function(x, annot, .matrix) {

annotation_rows <- function(x) {
if (is.null(attr(x, "rows_annotation"))) {
tibble_pole(nrow(get_rows(x)))
tibble(.rows = nrow(get_rows(x)))
} else {
attr(x, "rows_annotation")
}
}

annotation_cols <- function(x) {
if (is.null(attr(x, "cols_annotation"))) {
tibble_pole(nrow(get_cols(x)))
tibble(.rows = nrow(get_cols(x)))
} else {
attr(x, "cols_annotation")
}
Expand Down
4 changes: 0 additions & 4 deletions R/utils.r
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ method_classes <- function(generic.function) {
)
}

tibble_pole <- function(nrow) {
as_tibble(matrix(nrow = nrow, ncol = 0))
}

factor_coord <- function(x) {
if (any(duplicated(x))) stop("Duplicated coordinates detected.")
factor(x, levels = x)
Expand Down
34 changes: 25 additions & 9 deletions man/biplot-geoms.Rd

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

Loading

0 comments on commit 6724b0f

Please sign in to comment.