Skip to content

Commit

Permalink
change pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisorwa committed Oct 29, 2024
1 parent fb7816c commit 25d5e71
Show file tree
Hide file tree
Showing 86 changed files with 525 additions and 523 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ importFrom(ggplot2,aes)
importFrom(ggplot2,autoplot)
importFrom(ggplot2,ggplot)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
importFrom(mixtools,normalmixEM)
importFrom(rlang,.data)
importFrom(rlang,.env)
Expand Down
2 changes: 1 addition & 1 deletion R/add_point_to_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_point_to_graph <- function(
name = "est.incidence",
point_data =
tibble(

Check warning on line 6 in R/add_point_to_graph.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/add_point_to_graph.R,line=6,col=6,[indentation_linter] Indentation should be 8 spaces but is 6 spaces.
x = fit$estimate %>% exp(),
x = fit$estimate |> exp(),
y = log_likelihood(.data$x, ...),
label = "est.incidence"
),
Expand Down
10 changes: 5 additions & 5 deletions R/as_curve_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#' @examples
#' library(magrittr)
#' curve_data <-
#' "https://osf.io/download/rtw5k/" %>%
#' readr::read_rds() %>%
#' "https://osf.io/download/rtw5k/" |>
#' readr::read_rds() |>
#' as_curve_params()
#'
#' print(curve_data)
Expand All @@ -29,7 +29,7 @@ as_curve_params <- function(data, antigen_isos = NULL) {
}

curve_data <-
data %>%
data |>
tibble::as_tibble()

# check if object has expected columns:
Expand All @@ -38,7 +38,7 @@ as_curve_params <- function(data, antigen_isos = NULL) {
curve_cols <- c("antigen_iso", "y0", "y1", "t1", "alpha", "r")

# get columns from provided data
data_cols <- data %>% names()
data_cols <- data |> names()

# get any missing column(s)
missing_cols <- setdiff(x = curve_cols, y = data_cols)
Expand Down Expand Up @@ -70,7 +70,7 @@ as_curve_params <- function(data, antigen_isos = NULL) {
# assign antigen attribute
attr(curve_data, "antigen_isos") <- antigen_isos

curve_data <- curve_data %>%
curve_data <- curve_data |>
set_biomarker_var(biomarker = "antigen_iso", standardize = FALSE)

return(curve_data)
Expand Down
6 changes: 3 additions & 3 deletions R/as_noise_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#' @examples
#' library(magrittr)
#' noise_data <-
#' "https://osf.io/download//hqy4v/" %>%
#' readr::read_rds() %>%
#' "https://osf.io/download//hqy4v/" |>
#' readr::read_rds() |>
#' as_noise_params()
#'
#' print(noise_data)
Expand All @@ -31,7 +31,7 @@ as_noise_params <- function(data, antigen_isos = NULL) {
)
}

noise_data <- data %>% tibble::as_tibble()
noise_data <- data |> tibble::as_tibble()

# Define noise columns
noise_cols <- c("antigen_iso", "y.low", "eps", "nu", "y.high")
Expand Down
14 changes: 7 additions & 7 deletions R/as_pop_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#' @examples
#' library(magrittr)
#' xs_data <-
#' "https://osf.io/download//n6cp3/" %>%
#' readr::read_rds() %>%
#' "https://osf.io/download//n6cp3/" |>
#' readr::read_rds() |>
#' as_pop_data()
#'
#' print(xs_data)
Expand All @@ -25,7 +25,7 @@ as_pop_data <- function(data,


pop_data <-
data %>%
data |>
tibble::as_tibble()

class(pop_data) <-
Expand All @@ -39,10 +39,10 @@ as_pop_data <- function(data,

attr(pop_data, "antigen_isos") <- antigen_isos

pop_data <- pop_data %>%
set_age(age = age, standardize = standardize) %>%
set_value(value = value, standardize = standardize) %>%
set_id(id = id, standardize = standardize) %>%
pop_data <- pop_data |>
set_age(age = age, standardize = standardize) |>
set_value(value = value, standardize = standardize) |>
set_id(id = id, standardize = standardize) |>
set_biomarker_var(biomarker = "antigen_iso", standardize = standardize)

return(pop_data)
Expand Down
14 changes: 7 additions & 7 deletions R/autoplot.curve_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#' library(ggplot2)
#' library(magrittr)
#'
#' curve = load_curve_params("https://osf.io/download/rtw5k/") %>%
#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>%
#' slice(1:100, .by = antigen_iso) %>% # Reduce dataset for this example
#' curve = load_curve_params("https://osf.io/download/rtw5k/") |>
#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |>
#' slice(1:100, .by = antigen_iso) |> # Reduce dataset for this example
#' autoplot()
#'
#' curve
Expand All @@ -35,13 +35,13 @@ autoplot.curve_params <- function(
antigen_isos = unique(object$antigen_iso),
ncol = min(3, length(antigen_isos)),
...) {
split_data <- object %>%
filter(.data$antigen_iso %in% antigen_isos) %>%
droplevels() %>%
split_data <- object |>
filter(.data$antigen_iso %in% antigen_isos) |>
droplevels() |>

Check warning on line 40 in R/autoplot.curve_params.R

View check run for this annotation

Codecov / codecov/patch

R/autoplot.curve_params.R#L38-L40

Added lines #L38 - L40 were not covered by tests
split(~antigen_iso)

labels <- names(split_data)
figs <- split_data %>%
figs <- split_data |>

Check warning on line 44 in R/autoplot.curve_params.R

View check run for this annotation

Codecov / codecov/patch

R/autoplot.curve_params.R#L44

Added line #L44 was not covered by tests
lapply(FUN = plot_curve_params_one_ab, ...)

for (i in seq_along(figs)) {
Expand Down
30 changes: 15 additions & 15 deletions R/autoplot.pop_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#' standardize = TRUE
#' )
#'
#' xs_data %>% autoplot(strata = "Country", type = "density")
#' xs_data %>% autoplot(strata = "Country", type = "age-scatter")
#' xs_data |> autoplot(strata = "Country", type = "density")
#' xs_data |> autoplot(strata = "Country", type = "age-scatter")
#' @export
autoplot.pop_data <- function(
object,
Expand Down Expand Up @@ -65,21 +65,21 @@ autoplot.pop_data <- function(
age_scatter <- function(
object,
strata = NULL,
age_var = object %>% get_age_var(),
value_var = object %>% get_value_var()) {
age_var = object |> get_age_var(),
value_var = object |> get_value_var()) {
# create default plotting

if (is.null(strata)) {
plot1 <-
object %>%
object |>
ggplot2::ggplot() +
ggplot2::aes(
x = .data[[age_var]],
y = .data[[value_var]]
)
} else {
plot1 <-
object %>%
object |>
ggplot2::ggplot() +
ggplot2::aes(
col = .data[[strata]],
Expand Down Expand Up @@ -120,9 +120,9 @@ density_plot <- function(
object,
strata = NULL,
log = FALSE,
value_var = object %>% get_value_var()) {
value_var = object |> get_value_var()) {
plot1 <-
object %>%
object |>
ggplot2::ggplot() +
ggplot2::aes(x = .data[[value_var]]) +
ggplot2::theme_linedraw() +
Expand All @@ -146,19 +146,19 @@ density_plot <- function(
if (log) {

min_nonzero_val <-
object %>%
get_value() %>%
purrr::keep(~ . > 0) %>%
object |>
get_value() |>
purrr::keep(~ . > 0) |>

Check warning on line 151 in R/autoplot.pop_data.R

View check run for this annotation

Codecov / codecov/patch

R/autoplot.pop_data.R#L149-L151

Added lines #L149 - L151 were not covered by tests
min()

max_val <-
object %>%
get_value() %>%
object |>
get_value() |>

Check warning on line 156 in R/autoplot.pop_data.R

View check run for this annotation

Codecov / codecov/patch

R/autoplot.pop_data.R#L155-L156

Added lines #L155 - L156 were not covered by tests
max()

breaks1 <- c(0, 10^seq(
min_nonzero_val %>% log10() %>% floor(),
max_val %>% log10() %>% ceiling()
min_nonzero_val |> log10() |> floor(),
max_val |> log10() |> ceiling()

Check warning on line 161 in R/autoplot.pop_data.R

View check run for this annotation

Codecov / codecov/patch

R/autoplot.pop_data.R#L160-L161

Added lines #L160 - L161 were not covered by tests
))

plot1 <- plot1 +
Expand Down
8 changes: 4 additions & 4 deletions R/autoplot.seroincidence.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
#'
#' xs_data <- load_pop_data("https://osf.io/download//n6cp3/")
#'
#' curve <- load_curve_params("https://osf.io/download/rtw5k/") %>%
#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>%
#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |>
#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |>
#' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example

Check warning on line 18 in R/autoplot.seroincidence.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/autoplot.seroincidence.R,line=18,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 86 characters.
#'
#' noise <- load_noise_params("https://osf.io/download//hqy4v/")
#'
#' est1 <- est.incidence(
#' pop_data = xs_data %>% filter(Country == "Pakistan"),
#' pop_data = xs_data |> filter(Country == "Pakistan"),
#' curve_param = curve,
#' noise_param = noise %>% filter(Country == "Pakistan"),
#' noise_param = noise |> filter(Country == "Pakistan"),
#' antigen_isos = c("HlyE_IgG", "HlyE_IgA"),
#' build_graph = TRUE
#' )
Expand Down
10 changes: 5 additions & 5 deletions R/autoplot.seroincidence.by.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
#' library(dplyr)
#' library(ggplot2)
#'
#' xs_data <- "https://osf.io/download//n6cp3/" %>%
#' xs_data <- "https://osf.io/download//n6cp3/" |>
#' load_pop_data()
#'
#' curve <- load_curve_params("https://osf.io/download/rtw5k/") %>%
#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>%
#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |>
#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |>
#' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example

Check warning on line 19 in R/autoplot.seroincidence.by.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/autoplot.seroincidence.by.R,line=19,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 86 characters.
#'
#' noise <- load_noise_params("https://osf.io/download//hqy4v/")
#'
#' est2 <- est.incidence.by(
#' strata = c("catchment"),
#' pop_data = xs_data %>% filter(Country == "Pakistan"),
#' pop_data = xs_data |> filter(Country == "Pakistan"),
#' curve_params = curve,
#' noise_params = noise %>% filter(Country == "Pakistan"),
#' noise_params = noise |> filter(Country == "Pakistan"),
#' antigen_isos = c("HlyE_IgG", "HlyE_IgA"),
#' #num_cores = 8, #Allow for parallel processing to decrease run time
#' build_graph = TRUE
Expand Down
10 changes: 5 additions & 5 deletions R/autoplot.summary.seroincidence.by.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
#'
#' xs_data <- load_pop_data("https://osf.io/download//n6cp3/")
#'
#' curve <- load_curve_params("https://osf.io/download/rtw5k/") %>%
#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>%
#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |>
#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |>
#' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example
#'
#' noise <- load_noise_params("https://osf.io/download//hqy4v/")
#'
#' est2 <- est.incidence.by(
#' strata = c("catchment"),
#' pop_data = xs_data %>% filter(Country == "Pakistan"),
#' pop_data = xs_data |> filter(Country == "Pakistan"),
#' curve_params = curve,
#' noise_params = noise %>% filter(Country == "Pakistan"),
#' noise_params = noise |> filter(Country == "Pakistan"),
#' antigen_isos = c("HlyE_IgG", "HlyE_IgA"),
#' #num_cores = 8 #Allow for parallel processing to decrease run time
#' )
Expand All @@ -42,7 +42,7 @@ autoplot.summary.seroincidence.by <- function(
shape = 1,
width = 0.001,
...) {
object %>%
object |>

Check warning on line 45 in R/autoplot.summary.seroincidence.by.R

View check run for this annotation

Codecov / codecov/patch

R/autoplot.summary.seroincidence.by.R#L45

Added line #L45 was not covered by tests
ggplot2::ggplot(
ggplot2::aes(
x = get(xvar),
Expand Down
2 changes: 1 addition & 1 deletion R/check_parallel_cores.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ check_parallel_cores <- function(num_cores) {

if (num_cores > (parallel::detectCores() - 1)) {
num_cores <-
num_cores %>%
num_cores |>

Check warning on line 6 in R/check_parallel_cores.R

View check run for this annotation

Codecov / codecov/patch

R/check_parallel_cores.R#L6

Added line #L6 was not covered by tests
min(parallel::detectCores() - 1)

warning(
Expand Down
14 changes: 7 additions & 7 deletions R/check_pop_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @export
#' @examples
#' library(dplyr)
#' xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") %>%
#' xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") |>
#' as_pop_data()
#' check_pop_data(xs_data, verbose = TRUE)
#'
Expand All @@ -23,24 +23,24 @@ check_pop_data <- function(pop_data, verbose = FALSE) {
}

missing_age <- is.element(
pop_data %>% get_age_var(),
pop_data %>% names()
pop_data |> get_age_var(),
pop_data |> names()
)

if (!missing_age) {
"Argument {.arg pop_data} is missing column
{.var {pop_data %>% get_age_var()}}(age, in years)" %>%
{.var {pop_data |> get_age_var()}}(age, in years)" |>
cli::cli_abort(class = "missing-var")
}

missing_value <- is.element(
pop_data %>% get_value_var(),
pop_data %>% names()
pop_data |> get_value_var(),
pop_data |> names()
)

if (!missing_value) {
"Argument {.arg pop_data} is missing column
{.var {pop_data %>% get_value_var()}} (antibody measurement)" %>%
{.var {pop_data |> get_value_var()}} (antibody measurement)" |>
cli::cli_abort(class = "missing-var")
}

Expand Down
Loading

0 comments on commit 25d5e71

Please sign in to comment.