Skip to content
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

switch pipes from %>% to |> #310

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: serocalculator
Title: Estimating Infection Rates from Serological Data
Version: 1.2.0.9022
Version: 1.2.0.9023
Authors@R: c(
person("Peter", "Teunis", , "[email protected]", role = c("aut", "cph"),
comment = "Author of the method and original code."),
Expand Down
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
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# serocalculator (development version)

## New features

* Added example datasets with documentation for examples and testing (#314)

* Improved error messaging for `autoplot.pop_data()` (#234).
Expand All @@ -26,6 +25,8 @@
(from <https://github.com/bcgov/ssdtools>) (#265)

## Internal changes
* Replace pipes to base R pipes (#310)

* Change default pipe setting (#312)

* Add test for missing strata in `est.incidence.by` (#227)
Expand Down
10 changes: 5 additions & 5 deletions R/add_point_to_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ add_point_to_graph <- function(
fit,
name = "est.incidence",
point_data =
tibble(
x = fit$estimate %>% exp(),
y = log_likelihood(.data$x, ...),
label = "est.incidence"
),
tibble(
x = fit$estimate |> exp(),
y = log_likelihood(.data$x, ...),
label = "est.incidence"
),
...) {
graph <-
graph +
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
23 changes: 13 additions & 10 deletions R/as_pop_data.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#' Load a cross-sectional antibody survey data set
#'
#' @param data a [data.frame()] or [tibble::tbl_df]
#' @param antigen_isos [character()] vector of antigen isotypes to be used in analyses
#' @param antigen_isos [character()] vector of antigen
#' isotypes to be used in analyses
#' @param age a [character()] identifying the age column
#' @param id a [character()] identifying the id column
#' @param value a [character()] identifying the value column
#' @param standardize a [logical()] to determine standardization of columns
#' @returns a `pop_data` object (a [tibble::tbl_df] with extra attribute `antigen_isos`)
#' @param standardize a [logical()] to determine
#' standardization of columns
#' @returns a `pop_data` object (a [tibble::tbl_df]
#' with extra attribute `antigen_isos`)
#' @export
#' @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 +28,7 @@ as_pop_data <- function(data,


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

class(pop_data) <-
Expand All @@ -39,10 +42,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 @@
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 @@
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 @@
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 @@
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
21 changes: 11 additions & 10 deletions R/autoplot.seroincidence.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' Plot the log-likelihood curve for the incidence rate estimate
#'
#' @param object a `seroincidence` object (from [est.incidence()])
#' @param log_x should the x-axis be on a logarithmic scale (`TRUE`) or linear scale (`FALSE`, default)?
#' @param log_x should the x-axis be on a logarithmic scale
#'(`TRUE`) or linear scale (`FALSE`, default)?
#' @param ... unused
#'
#' @return a [ggplot2::ggplot()]
Expand All @@ -13,34 +14,34 @@
#'
#' 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")) %>%
#' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example
#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |>
#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG
#' # Reduce dataset for the purposes of this example
#' slice(1:100, .by = antigen_iso)
#'
#' 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
#' )
#'
#' # Plot the log-likelihood curve
#' autoplot(est1)
#'
autoplot.seroincidence =
function(object, log_x = FALSE, ...)
{
to_return = attr(object, "ll_graph")
autoplot.seroincidence <-
function(object, log_x = FALSE, ...) {
to_return <- attr(object, "ll_graph")

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

View check run for this annotation

Codecov / codecov/patch

R/autoplot.seroincidence.R#L37

Added line #L37 was not covered by tests

if (is.null(to_return)) {
stop(
"Graphs cannot be extracted; ",
"`build_graph` was not `TRUE` in the call to `est.incidence()`"
)
figure <- NULL

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

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/autoplot.seroincidence.R,line=44,col=7,[object_usage_linter] local variable 'figure' assigned but may not be used
}

if (log_x) {
Expand Down
21 changes: 11 additions & 10 deletions R/autoplot.seroincidence.by.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@
#' @param object a '"seroincidence.by"' object (from [est.incidence.by()])
#' @param ncol number of columns to use for panel of plots
#' @inheritDotParams autoplot.seroincidence
#' @return an object of class `"ggarrange"`, which is a [ggplot2::ggplot()] or a [list()] of [ggplot2::ggplot()]s.
#' @return an object of class `"ggarrange"`,
#' which is a [ggplot2::ggplot()] or a [list()] of [ggplot2::ggplot()]s.
#' @export
#' @examples
#'
#' 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")) %>%
#' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example
#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |>
#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |>
#' # Reduce dataset for the purposes of this example
#' slice(1:100, .by = antigen_iso)
#'
#' 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 All @@ -33,7 +35,7 @@
#' # Plot the log-likelihood curve
#' autoplot(est2)
#'
autoplot.seroincidence.by = function(
autoplot.seroincidence.by <- function(
object,
ncol = min(3, length(object)),
...) {
Expand All @@ -52,8 +54,7 @@
labels <- names(object)
figs <- lapply(object, FUN = autoplot.seroincidence, ...)

for (i in 1:length(figs))
{
for (i in 1:length(figs)) {

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

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/autoplot.seroincidence.by.R,line=57,col=13,[seq_linter] 1:length(...) is likely to be wrong in the empty edge case. Use seq_along(...) instead.

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

View check run for this annotation

Codecov / codecov/patch

R/autoplot.seroincidence.by.R#L57

Added line #L57 was not covered by tests
figs[[i]] <- figs[[i]] + ggplot2::ggtitle(labels[i])
}

Expand Down
Loading
Loading