Skip to content

Commit 649ba28

Browse files
authored
Issues/98 (#99)
* edits based on lintr checks * changes based on lintr * suppressMessages when loading magrittr * Don't print logs
1 parent b9a6178 commit 649ba28

28 files changed

Lines changed: 119 additions & 105 deletions

R/correlation_threshold.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#'
1717
#' @examples
1818
#'
19-
#' library(magrittr)
19+
#' suppressMessages(suppressWarnings(library(magrittr)))
2020
#' sample <- tibble::data_frame(
2121
#' x = rnorm(30),
2222
#' y = rnorm(30)/1000

R/count_na_rows.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ count_na_rows <- function(population, variables) {
2929
dplyr::summarize_at(variables, dplyr::funs(sum)) %>%
3030
dplyr::collect() %>%
3131
data.frame()
32-
3332
}

R/drop_na_columns.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
#' @export
2626
drop_na_columns <- function(population, variables, cutoff = 0.05) {
2727
cutoff <- rlang::enquo(cutoff)
28-
28+
2929
nrows <-
3030
population %>%
3131
dplyr::tally() %>%
3232
dplyr::collect() %>%
3333
magrittr::extract2("n")
3434

3535
count <- rlang::sym("count")
36-
36+
3737
feature <- rlang::sym("feature")
38-
38+
3939
percent <- rlang::sym("percent")
4040

4141
population %>%
@@ -44,6 +44,6 @@ drop_na_columns <- function(population, variables, cutoff = 0.05) {
4444
dplyr::collect() %>%
4545
tidyr::gather(!!feature, !!count, !!!variables) %>%
4646
dplyr::mutate(!!percent := (!!count) / nrows) %>%
47-
dplyr::filter((!!percent) > (!!cutoff)) %>%
47+
dplyr::filter( (!!percent) > (!!cutoff)) %>%
4848
magrittr::extract2("feature")
4949
}

R/drop_na_rows.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
drop_na_rows <- function(population, variables) {
2626

2727
key <- rlang::sym("key")
28-
28+
2929
value <- rlang::sym("value")
30-
30+
3131
rowname_temp <- rlang::sym("rowname_temp")
3232

3333
if (is.data.frame(population)) {
@@ -37,13 +37,13 @@ drop_na_rows <- function(population, variables) {
3737
dplyr::filter(!is.na(!!value)) %>%
3838
tidyr::spread(!!key, !!value) %>%
3939
dplyr::select(-!!rowname_temp)
40-
41-
} else {
42-
40+
41+
} else {
42+
4343
# Coalesce() must have at least 2 arguments.
44-
if(length(variables) == 1)
44+
if (length(variables) == 1)
4545
variables <- c(variables, variables)
46-
46+
4747
population %>%
4848
dplyr::filter_(.dots =
4949
sprintf("!is.null(coalesce(%s))",

R/generalized_log.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ generalized_log <- function(population, variables, offset = 1) {
2727
x <- rlang::sym(variable)
2828

2929
population %<>%
30-
dplyr::mutate(!!x := log( ((!!x) + ((!!x) ^ 2 + (!!offset) ^ 2) ^ 0.5 ) / 2))
30+
dplyr::mutate(!!x :=
31+
log( ( (!!x) + ( (!!x) ^ 2 + (!!offset) ^ 2) ^ 0.5 ) / 2))
3132
}
3233

3334
population
3435
}
35-

R/normalize.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' @importFrom stats cor mad median sd setNames
1818
#'
1919
#' @examples
20-
#' library(magrittr)
20+
#' suppressMessages(suppressWarnings(library(magrittr)))
2121
#' population <- tibble::data_frame(
2222
#' Metadata_group = c("control", "control", "control", "control",
2323
#' "experiment", "experiment", "experiment", "experiment"),
@@ -30,7 +30,8 @@
3030
#' cytominer::normalize(population, variables, strata, sample, operation = "standardize")
3131
#'
3232
#' @export
33-
normalize <- function(population, variables, strata, sample, operation = "standardize", ...) {
33+
normalize <- function(population, variables, strata, sample,
34+
operation = "standardize", ...) {
3435
scale <- function(data, location, dispersion, variables) {
3536
if (is.data.frame(data)) {
3637
futile.logger::flog.debug(paste0("\t\tUsing base::scale (data is ",
@@ -59,7 +60,7 @@ normalize <- function(population, variables, strata, sample, operation = "standa
5960
s <- dispersion[[variable]]
6061

6162
data %<>%
62-
dplyr::mutate(!!x := ((!!x) - m) / s )
63+
dplyr::mutate(!!x := ( (!!x) - m) / s )
6364

6465
}
6566

R/replicate_correlation.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ replicate_correlation <-
8282
strata <- c(strata, replicate_by)
8383
}
8484

85-
foreach::foreach(variable = variables, .combine = rbind) %dopar%
86-
{
85+
foreach::foreach(variable = variables, .combine = rbind) %dopar% {
8786

8887
sample %>%
8988
split(.[split_by]) %>%
@@ -94,7 +93,8 @@ replicate_correlation <-
9493
dplyr::arrange_(.dots = strata) %>%
9594
dplyr::select_(.dots = c(strata, variable, replicate_by)) %>%
9695
tidyr::spread_(replicate_by, variable) %>%
97-
dplyr::select_(~-dplyr::one_of(setdiff(strata, replicate_by))) %>%
96+
dplyr::select_(~-dplyr::one_of(setdiff(strata,
97+
replicate_by))) %>%
9898
stats::cor()
9999
median(correlation_matrix[upper.tri(correlation_matrix)])
100100
}) %>%

R/transform.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#' @importFrom magrittr %>%
2121
#' @importFrom magrittr %<>%
2222
#' @export
23-
transform <- function(population, variables, operation = "generalized_log", ...) {
23+
transform <- function(population, variables,
24+
operation = "generalized_log", ...) {
2425
if (operation == "generalized_log") {
2526
generalized_log(population, variables, ...)
2627
} else {

R/variable_importance.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@
4545
#' @importFrom magrittr %>%
4646
#' @importFrom magrittr %<>%
4747
#' @export
48-
variable_importance <- function(sample, variables, operation = "replicate_correlation", ...) {
48+
variable_importance <- function(sample, variables,
49+
operation = "replicate_correlation", ...) {
4950
if (operation == "replicate_correlation") {
5051
importance <- replicate_correlation(sample, variables, ...)
51-
52+
5253
} else {
5354
error <- paste0("undefined operation `", operation, "'")
5455

5556
futile.logger::flog.error(msg = error)
5657

5758
stop(error)
58-
59+
5960
}
6061

6162
importance

R/variable_select.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#' # In this example, we use `correlation_threshold` as the operation for
1616
#' # variable selection.
1717
#'
18-
#' library(magrittr)
18+
#' suppressMessages(suppressWarnings(library(magrittr)))
1919
#' population <- tibble::data_frame(
2020
#' x = rnorm(100),
2121
#' y = rnorm(100)/1000
@@ -35,6 +35,8 @@
3535
#'
3636
#' head(population)
3737
#'
38+
#' futile.logger::flog.threshold(futile.logger::ERROR)
39+
#'
3840
#' variable_select(population, variables, sample, operation) %>% head()
3941
#'
4042
#' @importFrom magrittr %>%

0 commit comments

Comments
 (0)