Skip to content

Commit

Permalink
refit_curves now updates all slots of intelliframe.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hefin Rhys committed Apr 9, 2024
1 parent 3647ddb commit a70cb44
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 37 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 19 additions & 9 deletions R/refit_curves.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

29 changes: 23 additions & 6 deletions R/update_curve_data.R
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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
}
4 changes: 1 addition & 3 deletions R/update_recovery.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")) |>

Expand Down
4 changes: 1 addition & 3 deletions R/update_recovery_avg.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions R/update_summary_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions R/update_well_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
4 changes: 3 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.onLoad <- function(libname, pkgname) {

if (getRversion() < "4.3.0") {
suppressPackageStartupMessages(requireNamespace("S7"))
suppressPackageStartupMessages(require("S7"))
}

S7::methods_register()
}
3 changes: 2 additions & 1 deletion man/plot_curves.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions man/update_curve_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions man/update_recovery.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions man/update_recovery_avg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions man/update_summary_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions man/update_well_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a70cb44

Please sign in to comment.