-
Notifications
You must be signed in to change notification settings - Fork 24
refactor: convert magrittr %>% to base |> and ensure RHS calls use pa… #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
7e58cb6
77d148c
dd21e31
329d8ba
b8a85f1
dec654e
35fa91b
84cd62c
dcf750c
35a95ca
ecd283d
02ced51
4f65dc4
41829e8
ae5ba5b
d4bb468
632259b
6115d9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |||||||||
| #' | ||||||||||
| #' @import dplyr | ||||||||||
| #' @import tidyr | ||||||||||
| #' @importFrom magrittr "%>%" | ||||||||||
| #' @importFrom magrittr "|>" | ||||||||||
| #' @importFrom rlang enquo | ||||||||||
| #' @importFrom rlang quo_name | ||||||||||
| #' @importFrom circlize colorRamp2 | ||||||||||
|
|
@@ -70,75 +70,75 @@ input_heatmap = function(.data, | |||||||||
|
|
||||||||||
| # Arguments | ||||||||||
| arguments = | ||||||||||
| as.list(environment()) %>% | ||||||||||
| as.list(environment()) |> | ||||||||||
| c(list(.horizontal = .horizontal, .vertical = .vertical, .abundance = .abundance)) | ||||||||||
|
|
||||||||||
| # Check if palette discrete and continuous are lists | ||||||||||
| if(!is.list(palette_grouping) ) | ||||||||||
| stop("tidyHeatmap says: the arguments palette_discrete and palette_continuous must be lists. E.g., list(rep(\"#000000\", 20))") | ||||||||||
|
|
||||||||||
| # Check that there have at least one value in the heatmap | ||||||||||
| if(.data %>% filter(!!.abundance %>% is.na %>% not %>% as.logical) %>% nrow %>% equals(0)) | ||||||||||
| if(.data |> filter(!!.abundance |> is.na |> not |> as.logical) |> nrow()() |> equals(0)) | ||||||||||
|
||||||||||
| stop("tidyHeatmap says: your dataset does not have any non NA values") | ||||||||||
|
|
||||||||||
| # Get abundance matrix | ||||||||||
| abundance_tbl = | ||||||||||
| .data %>% | ||||||||||
| ungroup() %>% | ||||||||||
| .data |> | ||||||||||
| ungroup() |> | ||||||||||
|
|
||||||||||
| # Check if transform is needed | ||||||||||
| when( | ||||||||||
| is_function(transform) ~ | ||||||||||
| mutate(., !!.abundance := !!.abundance %>% transform()) %>% | ||||||||||
| mutate(., !!.abundance := !!.abundance |> transform()) |> | ||||||||||
|
|
||||||||||
| # Check if log introduced -Inf | ||||||||||
| when( | ||||||||||
|
|
||||||||||
| # NAN produced | ||||||||||
| filter(., !!.abundance %>% is.nan %>% as.logical) %>% nrow %>% gt(0) ~ stop("tidyHeatmap says: you applied a transformation that introduced NaN."), | ||||||||||
| filter(., !!.abundance |> is.nan |> as.logical) |> nrow()() |> gt(0) ~ stop("tidyHeatmap says: you applied a transformation that introduced NaN."), | ||||||||||
|
||||||||||
|
|
||||||||||
| # -Inf produced | ||||||||||
| pull(., !!.abundance) %>% min %>% equals(-Inf) ~ stop("tidyHeatmap says: you applied a transformation that introduced negative infinite .value, was it log? If so please use log1p."), | ||||||||||
| pull(., !!.abundance) |> min |> equals(-Inf) ~ stop("tidyHeatmap says: you applied a transformation that introduced negative infinite .value, was it log? If so please use log1p."), | ||||||||||
| ~(.) | ||||||||||
| ), | ||||||||||
| ~ (.) | ||||||||||
| ) %>% | ||||||||||
| ) |> | ||||||||||
|
|
||||||||||
| # If scale row | ||||||||||
| when( | ||||||||||
| scale %in% c("row", "both") ~ (.) %>% | ||||||||||
| nest(data = -!!.vertical) %>% | ||||||||||
| mutate(data = map(data, ~ .x %>% mutate(!!.abundance := !!.abundance %>% scale_robust()))) %>% | ||||||||||
| scale %in% c("row", "both") ~ (.) |> | ||||||||||
| nest(data = -!!.vertical) |> | ||||||||||
| mutate(data = map(data, ~ .x |> mutate(!!.abundance := !!.abundance |> scale_robust()))) |> | ||||||||||
| unnest(data), | ||||||||||
| ~ (.) | ||||||||||
| ) %>% | ||||||||||
| ) |> | ||||||||||
|
|
||||||||||
| # If scale column | ||||||||||
| when( | ||||||||||
| scale %in% c("column", "both") ~ (.) %>% | ||||||||||
| nest(data = -!!.horizontal) %>% | ||||||||||
| mutate(data = map(data, ~ .x %>% mutate(!!.abundance := !!.abundance %>% scale_robust()))) %>% | ||||||||||
| scale %in% c("column", "both") ~ (.) |> | ||||||||||
| nest(data = -!!.horizontal) |> | ||||||||||
| mutate(data = map(data, ~ .x |> mutate(!!.abundance := !!.abundance |> scale_robust()))) |> | ||||||||||
| unnest(data), | ||||||||||
| ~ (.) | ||||||||||
| ) %>% | ||||||||||
| ) |> | ||||||||||
|
|
||||||||||
| distinct(!!.vertical,!!.horizontal,!!.abundance) %>% | ||||||||||
| distinct(!!.vertical,!!.horizontal,!!.abundance) |> | ||||||||||
|
|
||||||||||
| # Arrange both columns and rows | ||||||||||
| # do not leave the order of appearence dictate the order of columns and rows | ||||||||||
| pivot_wider(names_from = !!.horizontal, values_from = !!.abundance, names_sort = TRUE) |> | ||||||||||
| arrange(!!.vertical) | ||||||||||
|
|
||||||||||
| abundance_mat = | ||||||||||
| abundance_tbl %>% | ||||||||||
| abundance_tbl |> | ||||||||||
| as_matrix(rownames = quo_name(.vertical)) | ||||||||||
|
|
||||||||||
| # Colors tiles | ||||||||||
| # If palette_value is a function pass it directly, otherwise check if the character array is of length 3 | ||||||||||
| colors = | ||||||||||
| palette_value %>% | ||||||||||
| palette_value |> | ||||||||||
| when( | ||||||||||
| palette_value %>% class() %>% equals("function") ~ (.), | ||||||||||
| palette_value |> class()() |> equals("function") ~ (.), | ||||||||||
|
||||||||||
| palette_value |> class()() |> equals("function") ~ (.), | |
| palette_value |> class() |> equals("function") ~ (.), |
Outdated
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double parentheses nrow()() indicate incorrect syntax. The function should be called as nrow() after the pipe operator.
| how_many_groups = my_input_heatmap@data |> attr("groups") |> nrow()() | |
| how_many_groups = my_input_heatmap@data |> attr("groups") |> nrow() |
Outdated
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double parentheses ncol()() indicate incorrect syntax. The function should be called as ncol() after the pipe operator.
| how_many_grouping = my_input_heatmap@data |> attr("groups") |> select(-.rows) |> ncol()() | |
| how_many_grouping = my_input_heatmap@data |> attr("groups") |> select(-.rows) |> ncol() |
Outdated
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The importFrom directive references |> from magrittr, but |> is a base R pipe operator (available in R >= 4.1.0), not from the magrittr package. This line should be removed.
| #' @importFrom magrittr "|>" |
stemangiola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
stemangiola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
stemangiola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double parentheses nrow()() indicate incorrect syntax. The function should be called as nrow() after the pipe operator.
| how_many_discrete = .data_annot |> filter(annot_type=="discrete") |> nrow()() | |
| how_many_continuous = .data_annot |> filter(annot_type=="continuous") |> nrow()() | |
| how_many_discrete = .data_annot |> filter(annot_type=="discrete") |> nrow() | |
| how_many_continuous = .data_annot |> filter(annot_type=="continuous") |> nrow() |
Outdated
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The importFrom directive references |> from magrittr, but |> is a base R pipe operator (available in R >= 4.1.0), not from the magrittr package. This line should be removed.
| #' @importFrom magrittr "|>" |
stemangiola marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -330,7 +330,7 @@ heatmap_ <- | |||||
| ) |> | ||||||
|
|
||||||
| # Add group annotation if any | ||||||
| when( "groups" %in% (attributes(.data) |> names()) ~ add_grouping(.), ~ (.)) | ||||||
| when( "groups" %in% (attributes(.data) |> names()()) ~ add_grouping(.), ~ (.)) | ||||||
|
||||||
| when( "groups" %in% (attributes(.data) |> names()()) ~ add_grouping(.), ~ (.)) | |
| when( "groups" %in% (attributes(.data) |> names()) ~ add_grouping(.), ~ (.)) |
Outdated
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The importFrom directive references |> from magrittr, but |> is a base R pipe operator (available in R >= 4.1.0), not from the magrittr package. This line should be removed.
| #' @importFrom magrittr "|>" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,28 +10,28 @@ get_specific_annotation_columns = function(.data, .col){ | |||||
| .col = enquo(.col) | ||||||
|
|
||||||
| # x-annotation df | ||||||
| n_x = .data %>% select(!!.col) |> distinct() %>% nrow | ||||||
| n_x = .data |> select(!!.col) |> distinct() |> nrow()() | ||||||
|
||||||
| n_x = .data |> select(!!.col) |> distinct() |> nrow()() | |
| n_x = .data |> select(!!.col) |> distinct() |> nrow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The importFrom directive references
|>from magrittr, but|>is a base R pipe operator (available in R >= 4.1.0), not from the magrittr package. This line should be removed.