From 88d1b5ebd2f4d8e7b926762f4a9d9400e27553b0 Mon Sep 17 00:00:00 2001 From: "alex.hill@gmail.com" Date: Tue, 19 Nov 2024 13:28:11 +0000 Subject: [PATCH] Update docs, skip some plot tests if R < 4.1 --- NAMESPACE | 9 +++++ R/epikinetics-package.R | 4 ++- R/plot.R | 19 ++++++++-- man/biokinetics.Rd | 2 +- ...lot.biokinetics_individual_trajectories.Rd | 35 +++++++++++++++++++ ...iokinetics_population_stationary_points.Rd | 20 +++++++++++ tests/testthat/test-plots.R | 3 ++ 7 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 man/plot.biokinetics_individual_trajectories.Rd create mode 100644 man/plot.biokinetics_population_stationary_points.Rd diff --git a/NAMESPACE b/NAMESPACE index 577ae7a..615834d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,7 @@ # Generated by roxygen2: do not edit by hand +S3method(plot,biokinetics_individual_trajectories) +S3method(plot,biokinetics_population_stationary_points) S3method(plot,biokinetics_population_trajectories) S3method(plot,biokinetics_priors) export(add_exposure_data) @@ -18,12 +20,19 @@ importFrom(data.table,.SD) importFrom(data.table,data.table) importFrom(ggplot2,aes) importFrom(ggplot2,facet_wrap) +importFrom(ggplot2,geom_hline) importFrom(ggplot2,geom_line) +importFrom(ggplot2,geom_path) importFrom(ggplot2,geom_point) importFrom(ggplot2,geom_ribbon) importFrom(ggplot2,geom_smooth) +importFrom(ggplot2,geom_vline) importFrom(ggplot2,ggplot) importFrom(ggplot2,guide_legend) importFrom(ggplot2,guides) +importFrom(ggplot2,labs) +importFrom(ggplot2,scale_x_continuous) +importFrom(ggplot2,scale_x_date) importFrom(ggplot2,scale_y_continuous) +importFrom(ggplot2,sec_axis) useDynLib(epikinetics, .registration = TRUE) diff --git a/R/epikinetics-package.R b/R/epikinetics-package.R index 35b5299..848b02d 100644 --- a/R/epikinetics-package.R +++ b/R/epikinetics-package.R @@ -11,7 +11,9 @@ #' @importFrom data.table .NGRP #' @importFrom data.table .SD #' @importFrom data.table data.table -#' @importFrom ggplot2 aes facet_wrap geom_point geom_ribbon geom_line geom_smooth ggplot guides guide_legend scale_y_continuous +#' @importFrom ggplot2 aes facet_wrap geom_point geom_ribbon geom_line geom_smooth +#' geom_vline geom_hline geom_path labs ggplot guides guide_legend scale_y_continuous +#' scale_x_continuous scale_x_date sec_axis #' @useDynLib epikinetics, .registration = TRUE ## usethis namespace: end diff --git a/R/plot.R b/R/plot.R index ec38cc9..7d2bd55 100644 --- a/R/plot.R +++ b/R/plot.R @@ -85,7 +85,7 @@ plot.biokinetics_population_trajectories <- function(x, ..., data = NULL) { # Declare variables to suppress notes when compiling package # https://github.com/Rdatatable/data.table/issues/850#issuecomment-259466153 - time_since_last_exp <- value <- me <- titre_type <- lo <- hi <- NULL + time_since_last_exp <- value <- me <- mu <- .draw <- titre_type <- lo <- hi <- NULL day <- last_exp_day <- NULL if (attr(x, "summarised")) { @@ -124,7 +124,7 @@ plot.biokinetics_population_trajectories <- function(x, ..., data = NULL) { #' generated by running biokinetics$simulate_individual_trajectories(). See #' \href{../../epikinetics/html/biokinetics.html#method-biokinetics-simulate_individaul_trajectories}{\code{biokinetics$simulate_individual_trajectories()}} #' @param \dots Further arguments passed to the method. -#' @oaram min_day Optional minimum date +#' @param min_day Optional minimum date #' @param max_day Optional maximum date #' @param pid Optional vector of ids to plot simulated trajectories for a subset of individuals. Can only be used #' if x has been generated with summarise=FALSE. @@ -138,7 +138,9 @@ plot.biokinetics_individual_trajectories <- function(x, ..., data = NULL, # Declare variables to suppress notes when compiling package # https://github.com/Rdatatable/data.table/issues/850#issuecomment-259466153 - calendar_day <- value <- me <- mu <- titre_type <- lo <- hi <- day <- pid <- NULL + calendar_day <- value <- me <- mu <- titre_type <- day <- pid <- NULL + ind_mu_sum <- lo <- hi <- NULL + if (is.null(min_day)) { min_day <- min(x$calendar_day) } @@ -213,7 +215,18 @@ plot.biokinetics_individual_trajectories <- function(x, ..., data = NULL, fill = "none") } +#' Plot method for "biokinetics_population_stationary_points" class +#' +#' @param x An object of class "biokinetics_population_stationary_points". These are +#' generated by running biokinetics$population_stationary_points(). See +#' \href{../../epikinetics/html/biokinetics.html#method-biokinetics-population_stationary_points}{\code{biokinetics$population_stationary_points()}} +#' @param \dots Further arguments passed to the method. +#' @param upper_detection_limit Numeric. Optional upper detection limit. Will be plotted as a dotted line. +#' @export plot.biokinetics_population_stationary_points <- function(x, ..., upper_detection_limit = NULL) { + # Declare variables to suppress notes when compiling package + # https://github.com/Rdatatable/data.table/issues/850#issuecomment-259466153 + mu_p <- mu_s <- mu_p_me <- mu_s_me <- titre_type <- NULL covariates <- attr(x, "covariates") plot <- ggplot(data = x, aes(x = mu_p, y = mu_s, colour = titre_type)) + diff --git a/man/biokinetics.Rd b/man/biokinetics.Rd index 4e5f3f0..8f20194 100644 --- a/man/biokinetics.Rd +++ b/man/biokinetics.Rd @@ -286,7 +286,7 @@ Default TRUE.} \if{html}{\out{}} } \subsection{Returns}{ -A data.table. If summarise = TRUE columns are calendar_date, titre_type, me, lo, hi, time_shift. +A data.table. If summarise = TRUE columns are calendar_day, titre_type, me, lo, hi, time_shift. If summarise = FALSE, columns are pid, draw, time_since_last_exp, mu, titre_type, exposure_day, calendar_day, time_shift and a column for each covariate in the regression model. See the data vignette for details: \code{vignette("data", package = "epikinetics")}. diff --git a/man/plot.biokinetics_individual_trajectories.Rd b/man/plot.biokinetics_individual_trajectories.Rd new file mode 100644 index 0000000..2e188bf --- /dev/null +++ b/man/plot.biokinetics_individual_trajectories.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{plot.biokinetics_individual_trajectories} +\alias{plot.biokinetics_individual_trajectories} +\title{Plot method for "biokinetics_individual_trajectories" class} +\usage{ +\method{plot}{biokinetics_individual_trajectories}( + x, + ..., + data = NULL, + min_day = NULL, + max_day = NULL, + pids = NULL, + titre_types = NULL +) +} +\arguments{ +\item{x}{An object of class "biokinetics_individual_trajectories". These are +generated by running biokinetics$simulate_individual_trajectories(). See +\href{../../epikinetics/html/biokinetics.html#method-biokinetics-simulate_individaul_trajectories}{\code{biokinetics$simulate_individual_trajectories()}}} + +\item{\dots}{Further arguments passed to the method.} + +\item{min_day}{Optional minimum date} + +\item{max_day}{Optional maximum date} + +\item{titre_types}{Optional vector of titre types to include.} + +\item{pid}{Optional vector of ids to plot simulated trajectories for a subset of individuals. Can only be used +if x has been generated with summarise=FALSE.} +} +\description{ +Plot method for "biokinetics_individual_trajectories" class +} diff --git a/man/plot.biokinetics_population_stationary_points.Rd b/man/plot.biokinetics_population_stationary_points.Rd new file mode 100644 index 0000000..9c096fb --- /dev/null +++ b/man/plot.biokinetics_population_stationary_points.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot.R +\name{plot.biokinetics_population_stationary_points} +\alias{plot.biokinetics_population_stationary_points} +\title{Plot method for "biokinetics_population_stationary_points" class} +\usage{ +\method{plot}{biokinetics_population_stationary_points}(x, ..., upper_detection_limit = NULL) +} +\arguments{ +\item{x}{An object of class "biokinetics_population_stationary_points". These are +generated by running biokinetics$population_stationary_points(). See +\href{../../epikinetics/html/biokinetics.html#method-biokinetics-population_stationary_points}{\code{biokinetics$population_stationary_points()}}} + +\item{\dots}{Further arguments passed to the method.} + +\item{upper_detection_limit}{Numeric. Optional upper detection limit. Will be plotted as a dotted line.} +} +\description{ +Plot method for "biokinetics_population_stationary_points" class +} diff --git a/tests/testthat/test-plots.R b/tests/testthat/test-plots.R index 47fb73d..04bf1c3 100644 --- a/tests/testthat/test-plots.R +++ b/tests/testthat/test-plots.R @@ -218,6 +218,7 @@ test_that("Can plot individual trajectories for specific pids with data and titr }) test_that("Can plot stationary points", { + skip_if(getRversion() < 4.1) # note that this is using a pre-fitted model with very few iterations, so the # fits won't look very good local_mocked_bindings( @@ -231,6 +232,7 @@ test_that("Can plot stationary points", { }) test_that("Can plot stationary points with no covariates", { + skip_if(getRversion() < 4.1) # note that this is using a pre-fitted model with very few iterations, so the # fits won't look very good local_mocked_bindings( @@ -244,6 +246,7 @@ test_that("Can plot stationary points with no covariates", { test_that("Can plot stationary points with upper limit", { + skip_if(getRversion() < 4.1) # note that this is using a pre-fitted model with very few iterations, so the # fits won't look very good local_mocked_bindings(