Skip to content

Commit

Permalink
change results of correlate() class
Browse files Browse the repository at this point in the history
  • Loading branch information
Hy4m committed Feb 11, 2020
2 parents 43812fe + 7893bf5 commit bdfbe1f
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 60 deletions.
12 changes: 6 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
S3method(as.igraph,cor_network)
S3method(as.igraph,cor_tbl)
S3method(as.igraph,corr.test)
S3method(as.igraph,correlation)
S3method(as.igraph,correlate)
S3method(as.igraph,mantel_tbl)
S3method(as.igraph,rcorr)
S3method(as_cor_network,cor_tbl)
S3method(as_cor_network,corr.test)
S3method(as_cor_network,correlation)
S3method(as_cor_network,correlate)
S3method(as_cor_network,data.frame)
S3method(as_cor_network,default)
S3method(as_cor_network,igraph)
Expand All @@ -17,7 +17,7 @@ S3method(as_cor_network,matrix)
S3method(as_cor_network,rcorr)
S3method(as_cor_network,tbl_graph)
S3method(as_cor_tbl,corr.test)
S3method(as_cor_tbl,correlation)
S3method(as_cor_tbl,correlate)
S3method(as_cor_tbl,data.frame)
S3method(as_cor_tbl,default)
S3method(as_cor_tbl,mantel_tbl)
Expand All @@ -26,21 +26,21 @@ S3method(as_cor_tbl,rcorr)
S3method(as_tbl_graph,cor_network)
S3method(as_tbl_graph,cor_tbl)
S3method(as_tbl_graph,corr.test)
S3method(as_tbl_graph,correlation)
S3method(as_tbl_graph,correlate)
S3method(as_tbl_graph,mantel_tbl)
S3method(as_tbl_graph,rcorr)
S3method(as_tibble,cor_tbl)
S3method(display_cor,cor_tbl)
S3method(display_cor,corr.test)
S3method(display_cor,correlation)
S3method(display_cor,correlate)
S3method(display_cor,data.frame)
S3method(display_cor,mantel_tbl)
S3method(display_cor,matrix)
S3method(display_cor,rcorr)
S3method(export_cor_network,cor_network)
S3method(export_cor_network,cor_tbl)
S3method(export_cor_network,corr.test)
S3method(export_cor_network,correlation)
S3method(export_cor_network,correlate)
S3method(export_cor_network,data.frame)
S3method(export_cor_network,mantel_tbl)
S3method(export_cor_network,matrix)
Expand Down
4 changes: 2 additions & 2 deletions R/as-cor-network.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ as_cor_network.data.frame <- function(x, ...) {

#' @rdname as_cor_network
#' @export
#' @method as_cor_network correlation
as_cor_network.correlation <- function(x, ...) {
#' @method as_cor_network correlate
as_cor_network.correlate <- function(x, ...) {
cor_network(corr = x$r, p.value = x$p.value, ..., val.type = "list")
}

Expand Down
4 changes: 2 additions & 2 deletions R/as-cor-tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ as_cor_tbl.data.frame <- function(x, ...) {

#' @rdname as_cor_tbl
#' @export
#' @method as_cor_tbl correlation
as_cor_tbl.correlation <- function(x, extra.mat = list(), ...) {
#' @method as_cor_tbl correlate
as_cor_tbl.correlate <- function(x, extra.mat = list(), ...) {
anynull <- is.null(x$lower.ci) || is.null(x$upper.ci)
conf.ci <- if(!anynull) {
list(upper.ci = x$upper.ci, lower.ci = x$lower.ci)
Expand Down
2 changes: 1 addition & 1 deletion R/as-igraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ as.igraph.corr.test <- function(x, ...)

#' @rdname as_igraph
#' @export
as.igraph.correlation <- function(x, ...)
as.igraph.correlate <- function(x, ...)
{
cor_network(x$r, x$p.value, ..., val.type = "igraph")
}
Expand Down
2 changes: 1 addition & 1 deletion R/as-tbl-graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ as_tbl_graph.corr.test <- function(x, ...)

#' @rdname as_tbl_graph
#' @export
as_tbl_graph.correlation <- function(x, ...)
as_tbl_graph.correlate <- function(x, ...)
{
cor_network(x$r, x$p.value, ..., val.type = "graph_tbl")
}
Expand Down
41 changes: 20 additions & 21 deletions R/display-cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' the default value is 2.
#' @param sig.level significance level,the defaults values is `c(0.05, 0.01, 0.001)`.
#' @param mark significance mark,the defaults values is `c("*", "**", "***")`.
#' @param nice.format a logical value indicating whether the output needs to be
#' @param nice.format a logical value indicating whether the output needs to be
#' automatically optimized.
#' @param ... extra params passing to \code{\link[ggcor]{format_cor}}.
#' @return a data frame.
Expand Down Expand Up @@ -46,8 +46,8 @@ display_cor.data.frame <- function(x, ...) {

#' @rdname display_cor
#' @export
#' @method display_cor correlation
display_cor.correlation <- function(x, ...) {
#' @method display_cor correlate
display_cor.correlate <- function(x, ...) {
format_cor(corr = x$r, p.value = x$p.value, ...)
}

Expand All @@ -71,10 +71,10 @@ display_cor.corr.test <- function(x, ...) {
#' @rdname display_cor
#' @export
#' @method display_cor cor_tbl
display_cor.cor_tbl <- function(x,
display_cor.cor_tbl <- function(x,
type = "full",
show.diag = FALSE,
digits = 2,
digits = 2,
nsmall = 2,
sig.level = c(0.05, 0.01, 0.001),
mark = c("*", "**", "***"),
Expand All @@ -98,7 +98,7 @@ display_cor.cor_tbl <- function(x,
corr <- ifelse(x$r >= 0, paste0("", corr), corr)
}
if("p.value" %in% names(x) && is.numeric(x$p.value)) {
corr <- paste0(corr,
corr <- paste0(corr,
sig_mark(x$p.value, sig.level, mark))
}
max.len <- max(nchar(corr), na.rm = TRUE)
Expand All @@ -110,25 +110,25 @@ display_cor.cor_tbl <- function(x,
corr <- purrr::map_chr(corr, function(.corr) {
if(!is.na(.corr) && nchar(.corr) < max.len) {
paste0(.corr, paste0(rep_len(" ", max.len - nchar(.corr)), collapse = ""))
} else
} else
.corr
})
}

if(grouped) {
ngroup <- length(unique(x$.group))
mat <- matrix("", nrow = n * ngroup, ncol = m,

mat <- matrix("", nrow = n * ngroup, ncol = m,
dimnames = list(paste(rep(unique(x$.group), each = n),
rep(row.name, ngroup), sep = "-"),
rep(row.name, ngroup), sep = "-"),
col.name))
x <- split(x, x$.group)
name <- names(x)
x <- purrr::map_dfr(1:ngroup, function(.id) {
x[[.id]]$.row.id <<- n - x[[.id]]$.row.id + 1 + (.id - 1) * n
x[[.id]]
})

purrr::walk(1:nrow(x), function(.id) {
mat[x$.row.id[.id], x$.col.id[.id]] <<- corr[.id]
})
Expand All @@ -138,7 +138,7 @@ display_cor.cor_tbl <- function(x,
mat[n - x$.row.id[.id] + 1, x$.col.id[.id]] <<- corr[.id]
})
}

as.data.frame(mat, stringsAsFactors = FALSE, check.names = FALSE)
}

Expand All @@ -153,12 +153,11 @@ display_cor.mantel_tbl <- function(x, byrow = TRUE, ...) {
#' @importFrom purrr map_chr
#' @rdname display_cor
#' @export

format_cor <- function(corr,
format_cor <- function(corr,
p.value = NULL,
type = "full",
show.diag = FALSE,
digits = 2,
digits = 2,
nsmall = 2,
sig.level = c(0.05, 0.01, 0.001),
mark = c("*", "**", "***"),
Expand All @@ -169,17 +168,17 @@ format_cor <- function(corr,
if(!is.null(p.value) && !is.matrix(p.value))
p.value <- as.matrix(p.value)
type <- match.arg(type, c("full", "upper", "lower"))

idx <- corr >= 0
corr[] <- format_number(corr, digits, nsmall)
if(nice.format) {
corr[] <- ifelse(idx, paste0("", corr), corr)
}
if(!is.null(p.value)) {
corr[] <- paste0(corr,
corr[] <- paste0(corr,
sig_mark(p.value, sig.level, mark))
}

max.len <- max(nchar(corr), na.rm = TRUE)
if(!is.finite(max.len)) {
warning("Don't have finite value.", call. = FALSE)
Expand All @@ -191,11 +190,11 @@ format_cor <- function(corr,
corr[] <- purrr::map_chr(1:length(nn), function(.idx) {
if(nn[.idx] < max.len) {
paste0(corr[.idx], paste0(rep_len(" ", max.len - nn[.idx]), collapse = ""))
} else
} else
corr[.idx]
})
}

if(type == "upper") {
corr[lower.tri(corr, !show.diag)] <- ""
}
Expand Down
26 changes: 13 additions & 13 deletions R/export-cor-network.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,19 @@ export_cor_network.data.frame <- function(x,

#' @rdname export_cor_network
#' @export
#' @method export_cor_network correlation
export_cor_network.correlation <- function(x,
file = "",
what = "edges",
sep = ",",
row.names = NULL,
col.names = NULL,
rm.dup = TRUE,
simplify = TRUE,
r.thres = 0.6,
r.absolute = TRUE,
p.thres = 0.05,
...)
#' @method export_cor_network correlate
export_cor_network.correlate <- function(x,
file = "",
what = "edges",
sep = ",",
row.names = NULL,
col.names = NULL,
rm.dup = TRUE,
simplify = TRUE,
r.thres = 0.6,
r.absolute = TRUE,
p.thres = 0.05,
...)
{
what <- match.arg(what, c("edges", "nodes"))
x <- as_cor_network(x, row.names = row.names, col.names = col.names,
Expand Down
2 changes: 1 addition & 1 deletion R/fortify-cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fortify_cor <- function(x,
lower = get_lower_data(x, show.diag)
))
}
clss <- c("correlation", "rcorr", "corr.test", "mantel_tbl")
clss <- c("correlate", "rcorr", "corr.test", "mantel_tbl")
if(any(clss %in% class(x)) || is.cor) {
return(as_cor_tbl(x, type = type, show.diag = show.diag, cluster = cluster,
cluster.method = cluster.method, ...))
Expand Down
4 changes: 2 additions & 2 deletions man/as_cor_network.Rd

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

4 changes: 2 additions & 2 deletions man/as_cor_tbl.Rd

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

4 changes: 2 additions & 2 deletions man/as_igraph.Rd

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

4 changes: 2 additions & 2 deletions man/as_tbl_graph.Rd

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

6 changes: 3 additions & 3 deletions man/display_cor.Rd

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

4 changes: 2 additions & 2 deletions man/export_cor_network.Rd

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

0 comments on commit bdfbe1f

Please sign in to comment.