diff --git a/DESCRIPTION b/DESCRIPTION index a7f6812..017675c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,9 +32,9 @@ Imports: scales, nplr, utils, - mathjaxr + mathjaxr, + S7 Config/testthat/edition: 3 Depends: - R (>= 3.0), - S7 + R (>= 3.0) LazyData: true diff --git a/NAMESPACE b/NAMESPACE index 887453a..f6e27ea 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,10 +12,6 @@ export(intelliframe) export(plot_curves) export(read_xmap) export(refit_curves) -export(update_recovery) -export(update_recovery_avg) -export(update_summary_data) -export(update_well_data) importFrom(S7,props) importFrom(rlang,.data) importFrom(stats,reformulate) diff --git a/R/print.R b/R/print.R index b539b7b..30d27dc 100644 --- a/R/print.R +++ b/R/print.R @@ -6,7 +6,7 @@ #' @param ... Unused. #' #' @noRd -method(print, intelliframe) <- function(x, max.level = 1, ...) { +S7::method(print, intelliframe) <- function(x, max.level = 1, ...) { counts <- dplyr::summarise(get_well_data(x), .by = "Type", dplyr::n()) counts <- lapply(c("Standard", "Control", "Unknown"), function(.type) { diff --git a/R/refit_curves.R b/R/refit_curves.R index b8ee414..4840d6e 100644 --- a/R/refit_curves.R +++ b/R/refit_curves.R @@ -131,28 +131,38 @@ refit_curves <- function( names(fits) <- names(standard_list) - prop(intelliframe_out, "well_data") <- + S7::prop(intelliframe_out, "well_data") <- update_well_data(well_data, fits, standard_list, silent) - prop(intelliframe_out, "recovery") <- - update_recovery(well_data) + S7::prop(intelliframe_out, "recovery") <- + update_recovery( + S7::prop(intelliframe_out, "well_data") + ) - prop(intelliframe_out, "recovery_avg") <- + S7::prop(intelliframe_out, "recovery_avg") <- update_recovery_avg( - get_recovery(intelliframe_out), - get_recovery_avg(intelliframe_out), + S7::prop(intelliframe_out, "recovery"), + S7::prop(intelliframe_out, "recovery_avg"), use_excluded, excluded_wells ) - prop(intelliframe_out, "summary_data") <- + S7::prop(intelliframe_out, "summary_data") <- update_summary_data( - well_data, - get_summary_data(intelliframe_out), + S7::prop(intelliframe_out, "well_data"), + S7::prop(intelliframe_out, "summary_data"), use_excluded, excluded_wells ) + S7::prop(intelliframe_out, "curve_data") <- + update_curve_data( + S7::prop(intelliframe_out, "summary_data"), + S7::prop(intelliframe_out, "well_data"), + fits, + silent + ) + intelliframe_out } diff --git a/R/update_curve_data.R b/R/update_curve_data.R index f772f92..16856d3 100644 --- a/R/update_curve_data.R +++ b/R/update_curve_data.R @@ -1,6 +1,18 @@ -update_well_data <- function(.summary_data, .well_data, .fits, .standard_list, .silent) { +#' update_curve_data +#' +#' Update the curve_data property from an intelliframe object using a list of +#' model fits. Not meant to be called by the user. +#' +#' @param .summary_data A tibble containing the summary_data property. +#' @param .well_data A tibble containing the well_data property. +#' @param .fits A list of model fits returned by \code{nplr::nplr()}. +#' @param .silent Should luminary warnings be printed? +#' +#' @return A tibble +#' +update_curve_data <- function(.summary_data, .well_data, .fits, .silent) { -lapply(names(.fits), function(x) { +new_curve_data <- lapply(names(.fits), function(x) { lloq <- dplyr::filter( .summary_data, @@ -53,10 +65,6 @@ lapply(names(.fits), function(x) { }) }) - if(!silent) { - warning("LLoQ, MDD, and LoD may be calculated differently than in Belysa. See ?refit_curves for details.") - } - if(.fits[[x]]@weightMethod == "res") { weight_meth <- paste0("(1/residual)^", .fits[[x]]@LPweight) } else if(.fits[[x]]@weightMethod == "sdw") { @@ -93,4 +101,13 @@ lapply(names(.fits), function(x) { Equation = model_eqn ) }) |> dplyr::bind_rows() + +if(!.silent) { + warning( + "LLoQ, MDD, and LoD may be calculated differently than in Belysa. See ?refit_curves for details.", + call. = FALSE + ) +} + +new_curve_data } diff --git a/R/update_recovery.R b/R/update_recovery.R index e139f14..ae010ee 100644 --- a/R/update_recovery.R +++ b/R/update_recovery.R @@ -5,10 +5,8 @@ #' #' @param .well_data A tibble containing the well_data property. #' -#' @return An intelliframe -#' @export +#' @return A tibble #' -#' @noRd update_recovery <- function(.well_data){ dplyr::filter(.well_data, .data[["Type"]] %in% c("Standard", "Control")) |> diff --git a/R/update_recovery_avg.R b/R/update_recovery_avg.R index 499c47c..711cbf1 100644 --- a/R/update_recovery_avg.R +++ b/R/update_recovery_avg.R @@ -11,10 +11,8 @@ #' @param .excluded_wells Logical vector indicating whether each well is #' excluded. #' -#' @return An intelliframe -#' @export +#' @return A tibble #' -#' @noRd update_recovery_avg <- function(.recovery, .recovery_avg, .use_excluded, .excluded_wells) { correct_location <- dplyr::select(.recovery, -Location) |> dplyr::left_join( diff --git a/R/update_summary_data.R b/R/update_summary_data.R index 880a128..e338b21 100644 --- a/R/update_summary_data.R +++ b/R/update_summary_data.R @@ -11,10 +11,8 @@ #' @param .excluded_wells Logical vector indicating whether each well is #' excluded. #' -#' @return An intelliframe -#' @export +#' @return A tibble #' -#' @noRd update_summary_data <- function(.well_data, .summary_data, .use_excluded, .excluded_wells) { correct_location <- dplyr::select(.well_data, -Location) |> dplyr::left_join( diff --git a/R/update_well_data.R b/R/update_well_data.R index 310b99d..d0c3aa3 100644 --- a/R/update_well_data.R +++ b/R/update_well_data.R @@ -9,10 +9,8 @@ #' @param .silent Logical flag indicating whether warnings and messages during #' interpolation should be silenced. #' -#' @return An intelliframe -#' @export +#' @return A tibble #' -#' @noRd update_well_data <- function(.well_data, .fits, .standard_list, .silent) { lapply(names(.fits), function(analyte) { diff --git a/R/zzz.R b/R/zzz.R index 2933b3d..c4e32b2 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,6 +1,8 @@ .onLoad <- function(libname, pkgname) { + if (getRversion() < "4.3.0") { - suppressPackageStartupMessages(requireNamespace("S7")) + suppressPackageStartupMessages(require("S7")) } + S7::methods_register() } diff --git a/man/plot_curves.Rd b/man/plot_curves.Rd index ced0bc0..4df3369 100644 --- a/man/plot_curves.Rd +++ b/man/plot_curves.Rd @@ -34,7 +34,8 @@ or \code{"free"}.} \item{point_size}{Controls size of points drawn on the plot (defaults to 3).} \item{rug}{If \code{TRUE} (default) will add a "rug" of tickmarks to the x and y -axes to denote Unknown and Control samples.} +axes to denote Unknown and Control samples. Setting this to \code{FALSE} may speed +up rendering.} \item{model_limits}{If \code{TRUE} (default) will annotate the plots with lower limits of quantitation (LLoQ), limits of detection (LoD), and minimum diff --git a/man/update_curve_data.Rd b/man/update_curve_data.Rd new file mode 100644 index 0000000..7373f2e --- /dev/null +++ b/man/update_curve_data.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/update_curve_data.R +\name{update_curve_data} +\alias{update_curve_data} +\title{update_curve_data} +\usage{ +update_curve_data(.summary_data, .well_data, .fits, .silent) +} +\arguments{ +\item{.summary_data}{A tibble containing the curve_data property.} + +\item{.well_data}{A tibble containing the well_data property.} + +\item{.fits}{A list of model fits returned by \code{nplr::nplr()}.} + +\item{.silent}{Should luminary warnings be printed?} +} +\value{ +A tibble +} +\description{ +Update the curve_data property from an intelliframe object using a list of +model fits. Not meant to be called by the user. +} diff --git a/man/update_recovery.Rd b/man/update_recovery.Rd new file mode 100644 index 0000000..14045e7 --- /dev/null +++ b/man/update_recovery.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/update_recovery.R +\name{update_recovery} +\alias{update_recovery} +\title{update_recovery} +\usage{ +update_recovery(.well_data) +} +\arguments{ +\item{.well_data}{A tibble containing the well_data property.} +} +\value{ +A tibble +} +\description{ +Update the recovery property from an intelliframe object using up-to-date +well_data. Not meant to be called by the user. +} diff --git a/man/update_recovery_avg.Rd b/man/update_recovery_avg.Rd new file mode 100644 index 0000000..3262916 --- /dev/null +++ b/man/update_recovery_avg.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/update_recovery_avg.R +\name{update_recovery_avg} +\alias{update_recovery_avg} +\title{update_recovery_avg} +\usage{ +update_recovery_avg(.recovery, .recovery_avg, .use_excluded, .excluded_wells) +} +\arguments{ +\item{.recovery}{A tibble containing the original recovery_avg property.} + +\item{.use_excluded}{Logical flag indicating whether wells with a value of +\code{TRUE} in the \code{Excluded} column are used to calculate summary +statistics.} + +\item{.excluded_wells}{Logical vector indicating whether each well is +excluded.} +} +\value{ +A tibble +} +\description{ +Update the recovery_avg property from an intelliframe object using up-to-date +recovery. Not meant to be called by the user. +} diff --git a/man/update_summary_data.Rd b/man/update_summary_data.Rd new file mode 100644 index 0000000..90172ed --- /dev/null +++ b/man/update_summary_data.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/update_summary_data.R +\name{update_summary_data} +\alias{update_summary_data} +\title{update_summary_data} +\usage{ +update_summary_data(.well_data, .summary_data, .use_excluded, .excluded_wells) +} +\arguments{ +\item{.well_data}{A tibble containing the well_data property.} + +\item{.summary_data}{A tibble containing the original summary_data property.} + +\item{.use_excluded}{Logical flag indicating whether wells with a value of +\code{TRUE} in the \code{Excluded} column are used to calculate summary +statistics.} + +\item{.excluded_wells}{Logical vector indicating whether each well is +excluded.} +} +\value{ +A tibble +} +\description{ +Update the summary_data property from an intelliframe object using up-to-date +well_data Not meant to be called by the user. +} diff --git a/man/update_well_data.Rd b/man/update_well_data.Rd new file mode 100644 index 0000000..183f4a6 --- /dev/null +++ b/man/update_well_data.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/update_well_data.R +\name{update_well_data} +\alias{update_well_data} +\title{update_well_data} +\usage{ +update_well_data(.well_data, .fits, .standard_list, .silent) +} +\arguments{ +\item{.well_data}{A tibble containing the well_data property.} + +\item{.fits}{A list of model fits.} + +\item{.standard_list}{A tibble of standard curve data.} + +\item{.silent}{Logical flag indicating whether warnings and messages during +interpolation should be silenced.} +} +\value{ +A tibble +} +\description{ +Update the well_data property from an intelliframe object using a list of +model fits. Not meant to be called by the user. +}