lancer Example in Quarto

Author

Jeremy Selva

R Packages used

Code
r_package_table <- sessioninfo::package_info()
rownames(r_package_table) <- NULL

r_package_table |>
  dplyr::mutate(
    version = ifelse(is.na(r_package_table$loadedversion), 
                     r_package_table$ondiskversion, 
                     r_package_table$loadedversion)
  ) |> 
  dplyr::filter(.data$attached == TRUE) |> 
  dplyr::select(c("package", "version", 
                  "date", "source"
    )
  ) |> 
  reactable::reactable(
    columns = list(
      package = reactable::colDef(
        # Freeze first column
        sticky = "left",
        style = list(borderRight = "1px solid #eee"),
        headerStyle = list(borderRight = "1px solid #eee"))
  )
  )
package
version
date
source
lancer
0.1.1
2023-01-27
Github (SLINGhub/lancer@6703c2cd4a1ed860d664af9e1978842664af776a)
patchwork
1.1.2
2022-08-19
CRAN (R 4.2.2)
reactable
0.4.3
2023-01-07
CRAN (R 4.2.2)
report
0.5.5
2022-08-22
CRAN (R 4.2.2)
sessioninfo
1.2.2
2021-12-06
CRAN (R 4.2.2)
tibble
3.1.8
2022-07-22
CRAN (R 4.2.2)

R Platform Information

Code
# Taken from https://github.com/r-lib/sessioninfo/issues/75
get_quarto_version <- function() {
  if (isNamespaceLoaded("quarto")) {
    path <- quarto::quarto_path()
    ver <- system("quarto -V", intern = TRUE)
    if (is.null(path)) {
      "NA (via quarto)"
    } else {
      paste0(ver, " @ ", path, "/ (via quarto)")
    }
  } else {
    path <- Sys.which("quarto")
    if (path == "") {
      "NA"
    } else {
      ver <- system("quarto -V", intern = TRUE)
      paste0(ver, " @ ", path)
    }
  }
}

r_platform_table <- sessioninfo::platform_info()
r_platform_table[["quarto"]] <- get_quarto_version()[1]

r_platform_table <- data.frame(
    setting = names(r_platform_table),
    value = unlist(r_platform_table,
                   use.names = FALSE),
    stringsAsFactors = FALSE
  )

r_platform_table |>
  reactable::reactable(
    defaultPageSize = 5
  )
setting
value
version
R version 4.2.2 (2022-10-31 ucrt)
os
Windows 10 x64 (build 19045)
system
x86_64, mingw32
ui
RTerm
language
(EN)
1–5 of 11 rows

Data creation

Code
concentration <- c(
  10, 20, 25, 40, 50, 60,
  75, 80, 100, 125, 150,
  10, 25, 40, 50, 60,
  75, 80, 100, 125, 150)

curve_batch_name <- c(
  "B1", "B1", "B1", "B1", "B1",
  "B1", "B1", "B1", "B1", "B1", "B1",
  "B2", "B2", "B2", "B2", "B2",
  "B2", "B2", "B2", "B2", "B2")

sample_name <- c(
  "Sample_010a", "Sample_020a", "Sample_025a",
  "Sample_040a", "Sample_050a", "Sample_060a",
  "Sample_075a", "Sample_080a", "Sample_100a",
  "Sample_125a", "Sample_150a",
  "Sample_010b", "Sample_025b",
  "Sample_040b", "Sample_050b", "Sample_060b",
  "Sample_075b", "Sample_080b", "Sample_100b",
  "Sample_125b", "Sample_150b")

curve_1_saturation_regime <- c(
  5748124, 16616414, 21702718, 36191617,
  49324541, 55618266, 66947588, 74964771,
  75438063, 91770737, 94692060,
  5192648, 16594991, 32507833, 46499896,
  55388856, 62505210, 62778078, 72158161,
  78044338, 86158414)

curve_2_good_linearity <- c(
  31538, 53709, 69990, 101977, 146436, 180960,
  232881, 283780, 298289, 344519, 430432,
  25463, 63387, 90624, 131274, 138069,
  205353, 202407, 260205, 292257, 367924)

curve_3_noise_regime <- c(
  544, 397, 829, 1437, 1808, 2231,
  3343, 2915, 5268, 8031, 11045,
  500, 903, 1267, 2031, 2100,
  3563, 4500, 5300, 8500, 10430)

curve_4_poor_linearity <- c(
  380519, 485372, 478770, 474467, 531640, 576301,
  501068, 550201, 515110, 499543, 474745,
  197417, 322846, 478398, 423174, 418577,
  426089, 413292, 450190, 415309, 457618)

curve_batch_annot <- tibble::tibble(
  Sample_Name = sample_name,
  Curve_Batch_Name = curve_batch_name,
  Concentration = concentration
)

curve_data <- tibble::tibble(
  Sample_Name = sample_name,
  `Curve_1` = curve_1_saturation_regime,
  `Curve_2` = curve_2_good_linearity,
  `Curve_3` = curve_3_noise_regime,
  `Curve_4` = curve_4_poor_linearity
)
Code
curve_batch_annot |> 
  reactable::reactable(
    defaultPageSize = 5,
    bordered = TRUE,
    highlight = TRUE,
    paginationType = "jump"
    )
Sample_Name
Curve_Batch_Name
Concentration
Sample_010a
B1
10
Sample_020a
B1
20
Sample_025a
B1
25
Sample_040a
B1
40
Sample_050a
B1
50
1–5 of 21 rows
of 5
Code
curve_data |> 
  reactable::reactable(
    defaultPageSize = 5,
    bordered = TRUE,
    highlight = TRUE,
    paginationType = "jump"
    )
Sample_Name
Curve_1
Curve_2
Curve_3
Curve_4
Sample_010a
5748124
31538
544
380519
Sample_020a
16616414
53709
397
485372
Sample_025a
21702718
69990
829
478770
Sample_040a
36191617
101977
1437
474467
Sample_050a
49324541
146436
1808
531640
1–5 of 21 rows
of 5

Create curve table

Code
curve_table <- lancer::create_curve_table(
  curve_batch_annot, 
  curve_data,
  common_column = "Sample_Name",
  signal_var = "Signal",
  column_group = "Curve_Name"
)
Code
curve_table |> 
  reactable::reactable(
    defaultPageSize = 5,
    defaultColDef = reactable::colDef(
      minWidth = 200),
    bordered = TRUE,
    highlight = TRUE,
    paginationType = "jump"
)
Sample_Name
Curve_Batch_Name
Concentration
Curve_Name
Signal
Sample_010a
B1
10
Curve_1
5748124
Sample_010a
B1
10
Curve_2
31538
Sample_010a
B1
10
Curve_3
544
Sample_010a
B1
10
Curve_4
380519
Sample_020a
B1
20
Curve_1
16616414
1–5 of 84 rows
of 17

Create curve statistical summary

Code
curve_summary <- lancer::summarise_curve_table(
  curve_table,
  grouping_variable = c("Curve_Name",
                        "Curve_Batch_Name"),
  conc_var = "Concentration",
  signal_var = "Signal")

curve_classified <- lancer::evaluate_linearity(
  curve_summary,
  grouping_variable = c("Curve_Name",
                        "Curve_Batch_Name"))
Code
curve_summary |> 
  reactable::reactable(
    defaultPageSize = 5,
    defaultColDef = reactable::colDef(
      minWidth = 200), 
    bordered = TRUE,
    highlight = TRUE,
    paginationType = "jump"
)
Curve_Name
Curve_Batch_Name
r_corr
r2_linear
r2_adj_linear
mandel_stats
mandel_p_val
pra_linear
concavity
Curve_1
B1
0.963362
0.928067
0.920074
71.2051524704519
0.0000296859942893022
70.4941197744969
-4174.13330607923
Curve_2
B1
0.989903
0.979908
0.977675
2.53355237854347
0.15011382714456
92.7545599216462
-4.90717851815952
Curve_3
B1
0.964252
0.929783
0.921981
106.212174011867
0.00000677507948130652
71.1837175187664
0.46778274206258
Curve_4
B1
0.311458
0.097006
-0.003327
13.2417850636196
0.00659920775271108
-251.44936808119
-20.5225861852303
Curve_1
B2
0.950007
0.902514
0.890328
52.9344641262029
0.000166214861102321
62.3035079396165
-4136.52547570087
1–5 of 8 rows
of 2
Code
curve_classified |> 
  reactable::reactable(
    defaultPageSize = 5,
    defaultColDef = reactable::colDef(
      minWidth = 200),
    bordered = TRUE,
    highlight = TRUE,
    paginationType = "jump"
)
Curve_Name
Curve_Batch_Name
wf1_group
wf2_group
r_corr
pra_linear
mandel_p_val
concavity
r2_linear
r2_adj_linear
mandel_stats
Curve_1
B1
Poor Linearity
Saturation Regime
0.963362
70.4941197744969
0.0000296859942893022
-4174.13330607923
0.928067
0.920074
71.2051524704519
Curve_2
B1
Good Linearity
Good Linearity
0.989903
92.7545599216462
0.15011382714456
-4.90717851815952
0.979908
0.977675
2.53355237854347
Curve_3
B1
Poor Linearity
Noise Regime
0.964252
71.1837175187664
0.00000677507948130652
0.46778274206258
0.929783
0.921981
106.212174011867
Curve_4
B1
Poor Linearity
Poor Linearity
0.311458
-251.44936808119
0.00659920775271108
-20.5225861852303
0.097006
-0.003327
13.2417850636196
Curve_1
B2
Poor Linearity
Saturation Regime
0.950007
62.3035079396165
0.000166214861102321
-4136.52547570087
0.902514
0.890328
52.9344641262029
1–5 of 8 rows
of 2

Export results as Excel

Code
lancer::write_summary_excel(
  curve_classified, 
  file_name = "curve_summary.xlsx")

Export results as pdf

Code
ggplot_table <- lancer::add_ggplot_panel(
  curve_table,
  curve_summary = curve_classified,
  grouping_variable = c("Curve_Name",
                        "Curve_Batch_Name"),
  conc_var = "Concentration",
  signal_var = "Signal")

# Get the list of ggplot list for each group
ggplot_list <- ggplot_table$panel

lancer::view_ggplot_pdf(
  ggplot_list,
  filename = "curve_plot.pdf",
  ncol_per_page = 2,
  nrow_per_page = 2)
Code
patchwork::wrap_plots(
  ggplot_list,
  ncol = 2,
  nrow = 4
)

A display of dilution curves with summary statistics in ggplot.

Export results as trellis table

Code
trellis_table <- lancer::add_plotly_panel(
  curve_table,
  curve_summary = curve_classified,
  grouping_variable = c("Curve_Name",
                        "Curve_Batch_Name"),
  sample_name_var = "Sample_Name",
  curve_batch_var = "Curve_Batch_Name",
  curve_batch_col = c("#377eb8",
                      "#4daf4a"),
  conc_var = "Concentration",
  conc_var_units = "%",
  conc_var_interval = 50,
  signal_var = "Signal",
  have_plot_title = FALSE)

trellis_table <-  lancer::convert_to_cog(
  trellis_table,
  grouping_variable = c("Curve_Name",
                        "Curve_Batch_Name"),
  panel_variable = "panel",
  col_name_vec = "col_name_vec",
  desc_vec = "desc_vec",
  type_vec = "type_vec"
  )

# Pressing Render button will not create the 
# index.html file (Though it is not needed)
# Call this function via console to create index.html file
lancer::view_trellis_html(
  trellis_table,
  grouping_variable = c("Curve_Name",
                        "Curve_Batch_Name"),
  trellis_report_name = "Curve_Plot",
  trellis_report_folder = "Curve_Plot_Folder")
Curve_Plot

R Package Reference

Code