From 8ad7508cbda105a2ed70cd14170b4169b694147c Mon Sep 17 00:00:00 2001 From: Niklas Hohmann <67792281+NiklasHohmann@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:49:35 +0200 Subject: [PATCH 1/8] closes #11 --- vignettes/adm_from_sedrate.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/adm_from_sedrate.Rmd b/vignettes/adm_from_sedrate.Rmd index 94a4faa..d977f3a 100644 --- a/vignettes/adm_from_sedrate.Rmd +++ b/vignettes/adm_from_sedrate.Rmd @@ -251,7 +251,7 @@ Available wrappers to define sedimentation rates are - `sed_rate_gen_from_bounds` : generate sed. rate from upper and lower bounds on the sedimentation rate (see above) -- `sed_rate_from_matrix`: specify sedimentation rate based on matrix, to be used in conjunction with `get_data_from_eTimeOpt` +- `sed_rate_from_matrix`: specify sedimentation rate based on matrix, to be used in conjunction with `get_data_from_eTimeOpt`. This allows to have sedimentation rates change both at deterministic and randomized heights, see `?sed_rate_from_matrix` for details. ### Manually coding sedimentation rates From cc2baf9c04ea352d41ba30a59ee948b1f41146c9 Mon Sep 17 00:00:00 2001 From: Niklas Hohmann <67792281+NiklasHohmann@users.noreply.github.com> Date: Fri, 30 Aug 2024 09:08:20 +0200 Subject: [PATCH 2/8] extraction of tie points from multiadm --- NAMESPACE | 2 ++ R/get_L_tp.R | 8 +++++++- R/get_T_tp.R | 7 ++++++- man/get_L_tp.Rd | 2 +- man/get_T_tp.Rd | 2 +- vignettes/admtools_doc.Rmd | 3 ++- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index f654f42..cec7b26 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,11 +3,13 @@ S3method(condensation,adm) S3method(condensation,multiadm) S3method(get_L_tp,adm) +S3method(get_L_tp,multiadm) S3method(get_L_tp,sac) S3method(get_L_unit,adm) S3method(get_L_unit,multiadm) S3method(get_L_unit,sac) S3method(get_T_tp,adm) +S3method(get_T_tp,multiadm) S3method(get_T_tp,sac) S3method(get_T_unit,adm) S3method(get_T_unit,multiadm) diff --git a/R/get_L_tp.R b/R/get_L_tp.R index 0eff7f5..bd40126 100644 --- a/R/get_L_tp.R +++ b/R/get_L_tp.R @@ -3,7 +3,7 @@ get_L_tp = function(x, ...){ #' #' @title get height/length tie point #' - #' @param x age-depth model (adm) or sediment accumulation curve (sac) + #' @param x age-depth model (adm/multiadm) or sediment accumulation curve (sac) #' @param ... other options, currently not used #' #' @description @@ -26,4 +26,10 @@ get_L_tp.sac = function(x, ...){ #' @export #' return(x$h) +} + +get_L_tp.multiadm = function(x, ...){ + #' @export + #' + return(x$h) } \ No newline at end of file diff --git a/R/get_T_tp.R b/R/get_T_tp.R index f23c7d2..04fe4d7 100644 --- a/R/get_T_tp.R +++ b/R/get_T_tp.R @@ -3,7 +3,7 @@ get_T_tp = function(x, ...){ #' #' @title extract time tie points #' - #' @param x age-depth model (adm) or sediment accumulation curve (sac) + #' @param x age-depth model (adm/multiadm) or sediment accumulation curve (sac) #' @param ... other options, currently unused #' #' @description @@ -24,4 +24,9 @@ get_T_tp.adm = function(x, ...){ get_T_tp.sac = function(x, ...){ #' @export return(x$t) +} + +get_T_tp.multiadm = function(x, ...){ + #' @export + return(x$t) } \ No newline at end of file diff --git a/man/get_L_tp.Rd b/man/get_L_tp.Rd index a130cb7..a1fcd5f 100644 --- a/man/get_L_tp.Rd +++ b/man/get_L_tp.Rd @@ -7,7 +7,7 @@ get_L_tp(x, ...) } \arguments{ -\item{x}{age-depth model (adm) or sediment accumulation curve (sac)} +\item{x}{age-depth model (adm/multiadm) or sediment accumulation curve (sac)} \item{...}{other options, currently not used} } diff --git a/man/get_T_tp.Rd b/man/get_T_tp.Rd index 547f245..f0baff6 100644 --- a/man/get_T_tp.Rd +++ b/man/get_T_tp.Rd @@ -7,7 +7,7 @@ get_T_tp(x, ...) } \arguments{ -\item{x}{age-depth model (adm) or sediment accumulation curve (sac)} +\item{x}{age-depth model (adm/multiadm) or sediment accumulation curve (sac)} \item{...}{other options, currently unused} } diff --git a/vignettes/admtools_doc.Rmd b/vignettes/admtools_doc.Rmd index 0372351..6712657 100644 --- a/vignettes/admtools_doc.Rmd +++ b/vignettes/admtools_doc.Rmd @@ -92,7 +92,7 @@ The following functions extract information from `adm` objects: - `max_height.adm` extracts highest stratigraphic point in adm - `min_height.adm` extracts lowest stratigaphic point in adm - `min_time.adm` extracts timing of first tie point in adm -- `max_time.adm` extracts timing of last tie point in adm +- `max_time.adm` extracts timing of last tie point in adm - `get_L_tp` and `get_T_tp` to extract tie points. #### Transformation into other S3 classes @@ -215,6 +215,7 @@ The following functions extract information from `multiadm` objects: - `is_destructive` - `sed_rate_l` - `sed_rate_t` +- `get_T_tp` and `get_L_tp` to extract time and length/height tie points #### Transformation into other S3 classes From 76a37bcde90d08889651d87508715b631dded1fe Mon Sep 17 00:00:00 2001 From: Niklas Hohmann <67792281+NiklasHohmann@users.noreply.github.com> Date: Fri, 30 Aug 2024 09:17:05 +0200 Subject: [PATCH 3/8] implement get_total_duration for S3 class sac, condense architecture --- NAMESPACE | 1 + R/get_total_duration.R | 37 ++++++++++++++++++++++++++++++--- R/get_total_duration.adm.R | 8 ------- R/get_total_duration.multiadm.R | 13 ------------ vignettes/admtools_doc.Rmd | 1 + 5 files changed, 36 insertions(+), 24 deletions(-) delete mode 100644 R/get_total_duration.adm.R delete mode 100644 R/get_total_duration.multiadm.R diff --git a/NAMESPACE b/NAMESPACE index cec7b26..3be2182 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,6 +32,7 @@ S3method(get_time,adm) S3method(get_time,multiadm) S3method(get_total_duration,adm) S3method(get_total_duration,multiadm) +S3method(get_total_duration,sac) S3method(get_total_thickness,adm) S3method(get_total_thickness,multiadm) S3method(is_destructive,adm) diff --git a/R/get_total_duration.R b/R/get_total_duration.R index 0aecce0..a331006 100644 --- a/R/get_total_duration.R +++ b/R/get_total_duration.R @@ -1,14 +1,45 @@ -get_total_duration = function(x){ +get_total_duration = function(x, ...){ #' @export #' #' @title Total duration covered #' - #' @param x an adm object + #' @param x age-depth model (adm/multiadm) or sediment accumulation curve (sac) + #' @param ... other options, currently unused #' - #' @returns numeric vector, total duration covered by the age-depth models + #' @returns numeric, total duration covered by the age-depth models/sediment accumulation curve #' #' @seealso [min_time()] and [max_time()] to extract the first/last tie point in time #' UseMethod("get_total_duration") } + +get_total_duration.adm = function(x, ...){ + + #' + #' @export + #' + adm = x + return(diff(range(adm$t))) +} + +get_total_duration.multiadm = function(x, ...){ + #' + #' @export + #' + + multiadm = x + + adm_list = split_multiadm(multiadm) + + durations = sapply(adm_list, function(x) get_total_duration(x)) + return(durations) + +} + +get_total_duration.sac = function(x, ...){ + #' @export + #' + t = get_T_tp(x) + return(diff(range(t))) +} diff --git a/R/get_total_duration.adm.R b/R/get_total_duration.adm.R deleted file mode 100644 index 64b8368..0000000 --- a/R/get_total_duration.adm.R +++ /dev/null @@ -1,8 +0,0 @@ -get_total_duration.adm = function(x){ - - #' - #' @export - #' - adm = x - return(diff(range(adm$t))) -} diff --git a/R/get_total_duration.multiadm.R b/R/get_total_duration.multiadm.R deleted file mode 100644 index b82cc97..0000000 --- a/R/get_total_duration.multiadm.R +++ /dev/null @@ -1,13 +0,0 @@ -get_total_duration.multiadm = function(x){ - #' - #' @export - #' - - multiadm = x - - adm_list = split_multiadm(multiadm) - - durations = sapply(adm_list, function(x) get_total_duration(x)) - return(durations) - -} diff --git a/vignettes/admtools_doc.Rmd b/vignettes/admtools_doc.Rmd index 6712657..b92e599 100644 --- a/vignettes/admtools_doc.Rmd +++ b/vignettes/admtools_doc.Rmd @@ -146,6 +146,7 @@ The following functions extract information from `sac` objects: - `get_L_unit` and `get_T_unit` to extract units - `get_T_tp` and `get_L_tp` to extract tie points +- `get_total_duration` to extract total duration covered #### Transformation into other S3 classes From ffad4a7bb2ec3cad754349f4e86acaa28acb300c Mon Sep 17 00:00:00 2001 From: Niklas Hohmann <67792281+NiklasHohmann@users.noreply.github.com> Date: Fri, 30 Aug 2024 09:28:10 +0200 Subject: [PATCH 4/8] add get_total_thickness for S3 class sac, condense architecture --- NAMESPACE | 1 + R/get_total_thickness.R | 50 ++++++++++++++++++++--- R/get_total_thickness.adm.R | 10 ----- R/get_total_thickness.multiadm.R | 15 ------- man/get_total_duration.Rd | 8 ++-- man/get_total_thickness.Rd | 12 +++--- tests/testthat/test_get_total_thickness.R | 5 +++ vignettes/admtools_doc.Rmd | 1 + 8 files changed, 64 insertions(+), 38 deletions(-) delete mode 100644 R/get_total_thickness.adm.R delete mode 100644 R/get_total_thickness.multiadm.R diff --git a/NAMESPACE b/NAMESPACE index 3be2182..7b5f447 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -35,6 +35,7 @@ S3method(get_total_duration,multiadm) S3method(get_total_duration,sac) S3method(get_total_thickness,adm) S3method(get_total_thickness,multiadm) +S3method(get_total_thickness,sac) S3method(is_destructive,adm) S3method(is_destructive,multiadm) S3method(max_height,adm) diff --git a/R/get_total_thickness.R b/R/get_total_thickness.R index 279426e..e5df972 100644 --- a/R/get_total_thickness.R +++ b/R/get_total_thickness.R @@ -1,16 +1,56 @@ -get_total_thickness = function(x){ +get_total_thickness = function(x, ...){ #' #' #' @export #' - #' @title get thickness + #' @title get total thickness #' - #' @param x an adm object + #' @param x an age-depth model (adm/multiadm) or a sediment accumulation curve (sac) + #' @param ... other options, currently unused #' - #' @returns numeric vector containing total sediment thickness accumulated + #' @returns numeric, total sediment thickness accumulated + #' + #' @description + #' for sediment accumulation curves, returns the difference between the highest and lowest point of the curve. For age-depth models, returns the total thickness of sediment accumulated. + #' #' #' @seealso [max_height()] and [min_height()] to extract the highest/lowest stratigraphic point #' UseMethod("get_total_thickness") -} \ No newline at end of file +} + +get_total_thickness.multiadm = function(x, ...){ + + #' + #' @export + #' + + multiadm = x + + adm_list = split_multiadm(multiadm) + + thicknesses = sapply(adm_list, function(x) get_total_thickness(x)) + return(thicknesses) + + +} + + +get_total_thickness.adm = function(x, ...){ + + #' + #' @export + #' + #' + + adm = x + return(diff(range(adm$h))) +} + +get_total_thickness.sac = function(x, ...){ + #' @export + #' + h = get_L_tp(x) + return(diff(range(h))) +} diff --git a/R/get_total_thickness.adm.R b/R/get_total_thickness.adm.R deleted file mode 100644 index be6b2f5..0000000 --- a/R/get_total_thickness.adm.R +++ /dev/null @@ -1,10 +0,0 @@ -get_total_thickness.adm = function(x){ - - #' - #' @export - #' - #' - - adm = x - return(diff(range(adm$h))) -} diff --git a/R/get_total_thickness.multiadm.R b/R/get_total_thickness.multiadm.R deleted file mode 100644 index 9c3af21..0000000 --- a/R/get_total_thickness.multiadm.R +++ /dev/null @@ -1,15 +0,0 @@ -get_total_thickness.multiadm = function(x){ - - #' - #' @export - #' - - multiadm = x - - adm_list = split_multiadm(multiadm) - - thicknesses = sapply(adm_list, function(x) get_total_thickness(x)) - return(thicknesses) - - -} diff --git a/man/get_total_duration.Rd b/man/get_total_duration.Rd index 049c9f9..0b020a7 100644 --- a/man/get_total_duration.Rd +++ b/man/get_total_duration.Rd @@ -4,13 +4,15 @@ \alias{get_total_duration} \title{Total duration covered} \usage{ -get_total_duration(x) +get_total_duration(x, ...) } \arguments{ -\item{x}{an adm object} +\item{x}{age-depth model (adm/multiadm) or sediment accumulation curve (sac)} + +\item{...}{other options, currently unused} } \value{ -numeric vector, total duration covered by the age-depth models +numeric, total duration covered by the age-depth models/sediment accumulation curve } \description{ Total duration covered diff --git a/man/get_total_thickness.Rd b/man/get_total_thickness.Rd index fb61ee8..a13cc85 100644 --- a/man/get_total_thickness.Rd +++ b/man/get_total_thickness.Rd @@ -2,18 +2,20 @@ % Please edit documentation in R/get_total_thickness.R \name{get_total_thickness} \alias{get_total_thickness} -\title{get thickness} +\title{get total thickness} \usage{ -get_total_thickness(x) +get_total_thickness(x, ...) } \arguments{ -\item{x}{an adm object} +\item{x}{an age-depth model (adm/multiadm) or a sediment accumulation curve (sac)} + +\item{...}{other options, currently unused} } \value{ -numeric vector containing total sediment thickness accumulated +numeric, total sediment thickness accumulated } \description{ -get thickness +for sediment accumulation curves, returns the difference between the highest and lowest point of the curve. For age-depth models, returns the total thickness of sediment accumulated. } \seealso{ \code{\link[=max_height]{max_height()}} and \code{\link[=min_height]{min_height()}} to extract the highest/lowest stratigraphic point diff --git a/tests/testthat/test_get_total_thickness.R b/tests/testthat/test_get_total_thickness.R index 38e3289..34c79ae 100644 --- a/tests/testthat/test_get_total_thickness.R +++ b/tests/testthat/test_get_total_thickness.R @@ -7,3 +7,8 @@ test_that("returns correct thickness in standard case", { adm = tp_to_adm(t = c(1,2), h = c(1,2)) expect_equal(get_total_thickness(adm), 1) }) + +test_that("correct results for sac", { + sac = tp_to_sac(1:2, c(2, 1)) + expect_equal(get_total_thickness(sac), 1) +}) diff --git a/vignettes/admtools_doc.Rmd b/vignettes/admtools_doc.Rmd index b92e599..452d48c 100644 --- a/vignettes/admtools_doc.Rmd +++ b/vignettes/admtools_doc.Rmd @@ -147,6 +147,7 @@ The following functions extract information from `sac` objects: - `get_L_unit` and `get_T_unit` to extract units - `get_T_tp` and `get_L_tp` to extract tie points - `get_total_duration` to extract total duration covered +- `get_total_thickness` #### Transformation into other S3 classes From 988116c74f39510805600faa36b343bf6d230827 Mon Sep 17 00:00:00 2001 From: Niklas Hohmann <67792281+NiklasHohmann@users.noreply.github.com> Date: Fri, 30 Aug 2024 09:40:33 +0200 Subject: [PATCH 5/8] implement summary for S3 class sac, condense architecture --- NAMESPACE | 1 + R/summary.R | 76 ++++++++++++++++++++++++++++++++++++++ R/summary.adm.R | 29 --------------- R/summary.multiadm.R | 26 ------------- man/summary.adm.Rd | 2 +- man/summary.multiadm.Rd | 2 +- man/summary.sac.Rd | 19 ++++++++++ vignettes/admtools_doc.Rmd | 1 + 8 files changed, 99 insertions(+), 57 deletions(-) create mode 100644 R/summary.R delete mode 100644 R/summary.adm.R delete mode 100644 R/summary.multiadm.R create mode 100644 man/summary.sac.Rd diff --git a/NAMESPACE b/NAMESPACE index 7b5f447..82bc32c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -65,6 +65,7 @@ S3method(strat_to_time,numeric) S3method(strat_to_time,phylo) S3method(summary,adm) S3method(summary,multiadm) +S3method(summary,sac) S3method(time_to_strat,list) S3method(time_to_strat,numeric) S3method(time_to_strat,phylo) diff --git a/R/summary.R b/R/summary.R new file mode 100644 index 0000000..6ad4ab9 --- /dev/null +++ b/R/summary.R @@ -0,0 +1,76 @@ +summary.adm = function(object, ...){ + + #' @export + #' + #' @title summary of age-depth model + #' + #' @description + #' Displays some summary numbers of an age-depth models + #' + #' + #' @param object an adm object + #' @param ... other variables, are ignored + #' + #' @returns Invisible NULL, prints summary to the console + #' + #' @examples + #' my_adm = tp_to_adm(t = 1:5, h = c(2,2,3), L_unit = "m", T_unit = "Myr" ) + #' summary(my_adm) + #' + #' + + adm = object + cat("age-depth model \n") + cat("Total duration: ", get_total_duration(adm), " ", adm$T_unit, "\n", sep = "") + cat("Total thickness: ", get_total_thickness(adm), " ", adm$L_unit , "\n", sep = "") + cat("Stratigraphic completeness: ", get_completeness(adm) *100 , " % \n", sep = "") + cat( get_hiat_no(adm), "hiatus(es)") + return(invisible()) +} + +summary.multiadm = function(object, ...){ + + #' @export + #' + #' @title summary of age-depth model + #' + #' @description + #' Displays some summary numbers of an age-depth models + #' + #' + #' @param object a multiadm object + #' @param ... other variables, are ignored + #' + #' @returns Invisible NULL, prints summary to the console + #' + #' + #' + + adm = object + cat("multiple age-depth models \n") + cat("Median total duration: ", stats::median(get_total_duration(adm)), " ", adm$T_unit, "\n", sep = "") + cat("Median total thickness: ", stats::median(get_total_thickness(adm)), " ", adm$L_unit , "\n", sep = "") + cat("Median stratigraphic completeness: ", stats::median(get_completeness(adm) *100) , " % \n", sep = "") + cat( stats::median(get_hiat_no(adm)), "hiatus(es) (median)") + return(invisible()) +} + +summary.sac = function(object, ...){ + + #' @export + #' + #' @title summary of sediment accumulation curve + #' + #' @description + #' displays some summary numbers of sediment accumulation curve + #' + #' @param object sediment accumulation curve (sac) + #' @param ... other variables, are ignored + #' + #' @returns invisible NULL + cat("sediment accumulation curve\n") + cat("Total duration: ", get_total_duration.sac(object), " ", get_T_unit.sac(object), "\n", sep = "") + cat("Maximum thickness: ", get_total_thickness.sac(object), " ", get_L_unit.sac(object), "\n", sep = "") + + return(invisible()) +} \ No newline at end of file diff --git a/R/summary.adm.R b/R/summary.adm.R deleted file mode 100644 index 55ec11e..0000000 --- a/R/summary.adm.R +++ /dev/null @@ -1,29 +0,0 @@ -summary.adm = function(object, ...){ - - #' @export - #' - #' @title summary of age-depth model - #' - #' @description - #' Displays some summary numbers of an age-depth models - #' - #' - #' @param object an adm object - #' @param ... other variables, are ignored - #' - #' @returns Invisible NULL, prints summary to the console - #' - #' @examples - #' my_adm = tp_to_adm(t = 1:5, h = c(2,2,3), L_unit = "m", T_unit = "Myr" ) - #' summary(my_adm) - #' - #' - - adm = object - cat("age-depth model \n") - cat("Total duration: ", get_total_duration(adm), " ", adm$T_unit, "\n", sep = "") - cat("Total thickness: ", get_total_thickness(adm), " ", adm$L_unit , "\n", sep = "") - cat("Stratigraphic completeness: ", get_completeness(adm) *100 , " % \n", sep = "") - cat( get_hiat_no(adm), "hiatus(es)") - return(invisible()) -} diff --git a/R/summary.multiadm.R b/R/summary.multiadm.R deleted file mode 100644 index b7467e8..0000000 --- a/R/summary.multiadm.R +++ /dev/null @@ -1,26 +0,0 @@ -summary.multiadm = function(object, ...){ - - #' @export - #' - #' @title summary of age-depth model - #' - #' @description - #' Displays some summary numbers of an age-depth models - #' - #' - #' @param object a multiadm object - #' @param ... other variables, are ignored - #' - #' @returns Invisible NULL, prints summary to the console - #' - #' - #' - - adm = object - cat("multiple age-depth models \n") - cat("Median total duration: ", stats::median(get_total_duration(adm)), " ", adm$T_unit, "\n", sep = "") - cat("Median total thickness: ", stats::median(get_total_thickness(adm)), " ", adm$L_unit , "\n", sep = "") - cat("Median stratigraphic completeness: ", stats::median(get_completeness(adm) *100) , " % \n", sep = "") - cat( stats::median(get_hiat_no(adm)), "hiatus(es) (median)") - return(invisible()) -} \ No newline at end of file diff --git a/man/summary.adm.Rd b/man/summary.adm.Rd index fb15c57..c85fd65 100644 --- a/man/summary.adm.Rd +++ b/man/summary.adm.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/summary.adm.R +% Please edit documentation in R/summary.R \name{summary.adm} \alias{summary.adm} \title{summary of age-depth model} diff --git a/man/summary.multiadm.Rd b/man/summary.multiadm.Rd index 78aac72..c3e6d54 100644 --- a/man/summary.multiadm.Rd +++ b/man/summary.multiadm.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/summary.multiadm.R +% Please edit documentation in R/summary.R \name{summary.multiadm} \alias{summary.multiadm} \title{summary of age-depth model} diff --git a/man/summary.sac.Rd b/man/summary.sac.Rd new file mode 100644 index 0000000..419195e --- /dev/null +++ b/man/summary.sac.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/summary.R +\name{summary.sac} +\alias{summary.sac} +\title{summary of sediment accumulation curve} +\usage{ +\method{summary}{sac}(object, ...) +} +\arguments{ +\item{object}{sediment accumulation curve (sac)} + +\item{...}{other variables, are ignored} +} +\value{ +invisible NULL +} +\description{ +displays some summary numbers of sediment accumulation curve +} diff --git a/vignettes/admtools_doc.Rmd b/vignettes/admtools_doc.Rmd index 452d48c..68dffc6 100644 --- a/vignettes/admtools_doc.Rmd +++ b/vignettes/admtools_doc.Rmd @@ -133,6 +133,7 @@ The following functions yield a representation of `sac` objects: - `plot.sac` for plotting - `print.sac` for printing to the console +- `summary.sac` to provide a quick summary #### Modification From 1e7fa7e6a16cbf419080148e623305ed403a3245 Mon Sep 17 00:00:00 2001 From: Niklas Hohmann <67792281+NiklasHohmann@users.noreply.github.com> Date: Fri, 30 Aug 2024 09:55:02 +0200 Subject: [PATCH 6/8] implement utility functions for S3 class sac --- NAMESPACE | 4 ++++ R/max_heigth.R | 22 +++++++++++++++------- R/max_time.R | 20 ++++++++++++++------ R/min_height.R | 21 +++++++++++++++------ R/min_time.R | 21 +++++++++++++++------ man/max_height.Rd | 12 +++++++----- man/max_time.Rd | 12 +++++++----- man/min_height.Rd | 13 +++++++++---- man/min_time.Rd | 12 +++++++----- vignettes/admtools_doc.Rmd | 2 ++ 10 files changed, 95 insertions(+), 44 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 82bc32c..452c079 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -39,9 +39,13 @@ S3method(get_total_thickness,sac) S3method(is_destructive,adm) S3method(is_destructive,multiadm) S3method(max_height,adm) +S3method(max_height,sac) S3method(max_time,adm) +S3method(max_time,sac) S3method(min_height,adm) +S3method(min_height,sac) S3method(min_time,adm) +S3method(min_time,sac) S3method(plot,adm) S3method(plot,multiadm) S3method(plot,sac) diff --git a/R/max_heigth.R b/R/max_heigth.R index 51150cc..06fe40a 100644 --- a/R/max_heigth.R +++ b/R/max_heigth.R @@ -1,19 +1,27 @@ -max_height = function(x){ +max_height = function(x, ...){ #' @export #' - #' @title get highest stratigraphic position in an adm + #' @title get highest stratigraphic tie point #' - #' @param x an age-depth model + #' @param x age-depth model (adm) or sediment accumulation curve (sac) + #' @param ... other variables, ignored #' - #' @returns a scalar + #' @returns number, stratigraphic position of the highest stratigraphic tie point #' #' @seealso [min_height()], [get_total_thickness()] #' UseMethod("max_height") } -max_height.adm = function(x){ +max_height.adm = function(x, ...){ #' @export - - return(max(x$h)) + h = get_L_tp.adm(x) + return(max(h)) +} + +max_height.sac = function(x, ... ){ + #' @export + #' + h = get_L_tp.sac(x) + return(max(h)) } \ No newline at end of file diff --git a/R/max_time.R b/R/max_time.R index 8f2cae6..c21859c 100644 --- a/R/max_time.R +++ b/R/max_time.R @@ -1,19 +1,27 @@ -max_time = function(x){ +max_time = function(x, ...){ #' @export #' - #' @title extract earliest time from adm + #' @title last time tie point #' - #' @param x age-depth model + #' @param x age-depth model (adm) or sediment accumulation curve (sac) + #' @param ... other variables, ignored #' - #' @returns a scalar, timing of earliest tie point in the adm + #' @returns number, last time tie point of the age-depth model/sediment accumulation curve #' #' @seealso [min_time()], [get_total_duration()] #' UseMethod("max_time") } -max_time.adm = function(x){ +max_time.adm = function(x, ...){ #' @export #' - return(max(x$t)) + t = get_T_tp.adm(x) + return(max(t)) +} + +max_time.sac = function(x, ...){ + #' @export + t = get_T_tp.sac(x) + return(max(t)) } \ No newline at end of file diff --git a/R/min_height.R b/R/min_height.R index 75c8446..0e074d2 100644 --- a/R/min_height.R +++ b/R/min_height.R @@ -1,10 +1,13 @@ -min_height = function(x){ +min_height = function(x, ...){ #' @export #' - #' @title get lowest stratigraphic position in an adm + #' @title get lowest stratigraphic tie point #' - #' @param x an age-depth model + #' @param x an age-depth model (adm) or sediment accumulation curve (sac) + #' @param ... other parameters, ignored + #' + #' @returns number, stratigraphic position of lowest tie poin #' #' @seealso [get_total_thickness()], [max_height()] #' @@ -12,9 +15,15 @@ min_height = function(x){ } -min_height.adm = function(x){ +min_height.adm = function(x, ...){ #' @export - - return(min(x$h)) + h = get_L_tp.adm(x) + return(min(h)) +} + +min_height.sac = function(x, ...){ + #' @export + h = get_L_tp.sac(x) + return(min(h)) } \ No newline at end of file diff --git a/R/min_time.R b/R/min_time.R index 3d31ee2..d860722 100644 --- a/R/min_time.R +++ b/R/min_time.R @@ -1,19 +1,28 @@ -min_time = function(x){ +min_time = function(x, ...){ #' @export #' - #' @title extract last time from adm + #' @title first time tie point #' - #' @param x age-depth model + #' @param x age-depth model (adm) or sediment accumulation curve (sac) + #' @param ... other variables, ignored #' - #' @returns a scalar, timing of last tie point in the adm + #' @returns number, timing of first tie point of the age-depth model/sediment accumulation curve #' #' @seealso [max_time()], [get_total_duration()] #' UseMethod("min_time") } -min_time.adm = function(x){ +min_time.adm = function(x, ...){ #' @export #' - return(min(x$t)) + t = get_T_tp.adm(x) + return(min(t)) +} + +min_time.sac = function(x, ...){ + #' @export + #' + t = get_T_tp.sac(x) + return(min(t)) } \ No newline at end of file diff --git a/man/max_height.Rd b/man/max_height.Rd index 3ec17dc..576ca49 100644 --- a/man/max_height.Rd +++ b/man/max_height.Rd @@ -2,18 +2,20 @@ % Please edit documentation in R/max_heigth.R \name{max_height} \alias{max_height} -\title{get highest stratigraphic position in an adm} +\title{get highest stratigraphic tie point} \usage{ -max_height(x) +max_height(x, ...) } \arguments{ -\item{x}{an age-depth model} +\item{x}{age-depth model (adm) or sediment accumulation curve (sac)} + +\item{...}{other variables, ignored} } \value{ -a scalar +number, stratigraphic position of the highest stratigraphic tie point } \description{ -get highest stratigraphic position in an adm +get highest stratigraphic tie point } \seealso{ \code{\link[=min_height]{min_height()}}, \code{\link[=get_total_thickness]{get_total_thickness()}} diff --git a/man/max_time.Rd b/man/max_time.Rd index 4eaa3fc..8325eb8 100644 --- a/man/max_time.Rd +++ b/man/max_time.Rd @@ -2,18 +2,20 @@ % Please edit documentation in R/max_time.R \name{max_time} \alias{max_time} -\title{extract earliest time from adm} +\title{last time tie point} \usage{ -max_time(x) +max_time(x, ...) } \arguments{ -\item{x}{age-depth model} +\item{x}{age-depth model (adm) or sediment accumulation curve (sac)} + +\item{...}{other variables, ignored} } \value{ -a scalar, timing of earliest tie point in the adm +number, last time tie point of the age-depth model/sediment accumulation curve } \description{ -extract earliest time from adm +last time tie point } \seealso{ \code{\link[=min_time]{min_time()}}, \code{\link[=get_total_duration]{get_total_duration()}} diff --git a/man/min_height.Rd b/man/min_height.Rd index c8ffd8a..4ac3519 100644 --- a/man/min_height.Rd +++ b/man/min_height.Rd @@ -2,15 +2,20 @@ % Please edit documentation in R/min_height.R \name{min_height} \alias{min_height} -\title{get lowest stratigraphic position in an adm} +\title{get lowest stratigraphic tie point} \usage{ -min_height(x) +min_height(x, ...) } \arguments{ -\item{x}{an age-depth model} +\item{x}{an age-depth model (adm) or sediment accumulation curve (sac)} + +\item{...}{other parameters, ignored} +} +\value{ +number, stratigraphic position of lowest tie poin } \description{ -get lowest stratigraphic position in an adm +get lowest stratigraphic tie point } \seealso{ \code{\link[=get_total_thickness]{get_total_thickness()}}, \code{\link[=max_height]{max_height()}} diff --git a/man/min_time.Rd b/man/min_time.Rd index f3319fe..2a86a0c 100644 --- a/man/min_time.Rd +++ b/man/min_time.Rd @@ -2,18 +2,20 @@ % Please edit documentation in R/min_time.R \name{min_time} \alias{min_time} -\title{extract last time from adm} +\title{first time tie point} \usage{ -min_time(x) +min_time(x, ...) } \arguments{ -\item{x}{age-depth model} +\item{x}{age-depth model (adm) or sediment accumulation curve (sac)} + +\item{...}{other variables, ignored} } \value{ -a scalar, timing of last tie point in the adm +number, timing of first tie point of the age-depth model/sediment accumulation curve } \description{ -extract last time from adm +first time tie point } \seealso{ \code{\link[=max_time]{max_time()}}, \code{\link[=get_total_duration]{get_total_duration()}} diff --git a/vignettes/admtools_doc.Rmd b/vignettes/admtools_doc.Rmd index 68dffc6..1d5f7d0 100644 --- a/vignettes/admtools_doc.Rmd +++ b/vignettes/admtools_doc.Rmd @@ -149,6 +149,8 @@ The following functions extract information from `sac` objects: - `get_T_tp` and `get_L_tp` to extract tie points - `get_total_duration` to extract total duration covered - `get_total_thickness` +- `min_time` and `max_time` +- `min_height` and `max_height` #### Transformation into other S3 classes From b2b66962a96da7fcd0ba46e10a5fcb708a45b223 Mon Sep 17 00:00:00 2001 From: Niklas Hohmann <67792281+NiklasHohmann@users.noreply.github.com> Date: Fri, 30 Aug 2024 09:58:08 +0200 Subject: [PATCH 7/8] condense architecture --- R/print.R | 26 ++++++++++++++++++++++++++ R/print.adm.R | 9 --------- R/print.multiadm.R | 9 --------- R/print.sac.R | 6 ------ 4 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 R/print.R delete mode 100644 R/print.adm.R delete mode 100644 R/print.multiadm.R delete mode 100644 R/print.sac.R diff --git a/R/print.R b/R/print.R new file mode 100644 index 0000000..cd5a97b --- /dev/null +++ b/R/print.R @@ -0,0 +1,26 @@ +print.adm = function(x, ...){ + + #' + #' @export + #' @noRd + + cat("age-depth model") + return(invisible()) +} + +print.multiadm = function(x, ...){ + + #' + #' @export + #' @noRd + + cat("Collection of age-depth models") + return(invisible()) +} + +print.sac = function(x, ...){ + #' @export + #' @noRd + cat("sediment accumulation curve") + return(invisible()) +} \ No newline at end of file diff --git a/R/print.adm.R b/R/print.adm.R deleted file mode 100644 index 5e5904c..0000000 --- a/R/print.adm.R +++ /dev/null @@ -1,9 +0,0 @@ -print.adm = function(x, ...){ - - #' - #' @export - #' @noRd - - cat("age-depth model") - return(invisible()) -} \ No newline at end of file diff --git a/R/print.multiadm.R b/R/print.multiadm.R deleted file mode 100644 index bcd7e6c..0000000 --- a/R/print.multiadm.R +++ /dev/null @@ -1,9 +0,0 @@ -print.multiadm = function(x, ...){ - - #' - #' @export - #' @noRd - - cat("Collection of age-depth models") - return(invisible()) -} \ No newline at end of file diff --git a/R/print.sac.R b/R/print.sac.R deleted file mode 100644 index d052ba2..0000000 --- a/R/print.sac.R +++ /dev/null @@ -1,6 +0,0 @@ -print.sac = function(x, ...){ - #' @export - #' @noRd - cat("sediment accumulation curve") - return(invisible()) -} \ No newline at end of file From 19a8d617eaa19db47cb35a365d7a8e803b3df904 Mon Sep 17 00:00:00 2001 From: Niklas Hohmann <67792281+NiklasHohmann@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:15:26 +0200 Subject: [PATCH 8/8] remove superfluous ... --- NEWS.md | 4 +++- R/max_heigth.R | 7 +++---- R/max_time.R | 7 +++---- R/min_height.R | 7 +++---- R/min_time.R | 7 +++---- man/max_height.Rd | 4 +--- man/max_time.Rd | 4 +--- man/min_height.Rd | 4 +--- man/min_time.Rd | 4 +--- 9 files changed, 19 insertions(+), 29 deletions(-) diff --git a/NEWS.md b/NEWS.md index e800893..8dd06f3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,11 +4,13 @@ * abstracted exctraction of tie points +* added utility functions for S3 class `sac` + # admtools 0.3.0 * removed dependency from `ape` package -* defined S3 class `timelist` and `stratlist` for data assiciated with time/height +* defined S3 class `timelist` and `stratlist` for data associated with time/height * unified syntax for time-depth transformation diff --git a/R/max_heigth.R b/R/max_heigth.R index 06fe40a..6dd0a09 100644 --- a/R/max_heigth.R +++ b/R/max_heigth.R @@ -1,10 +1,9 @@ -max_height = function(x, ...){ +max_height = function(x){ #' @export #' #' @title get highest stratigraphic tie point #' #' @param x age-depth model (adm) or sediment accumulation curve (sac) - #' @param ... other variables, ignored #' #' @returns number, stratigraphic position of the highest stratigraphic tie point #' @@ -13,13 +12,13 @@ max_height = function(x, ...){ UseMethod("max_height") } -max_height.adm = function(x, ...){ +max_height.adm = function(x){ #' @export h = get_L_tp.adm(x) return(max(h)) } -max_height.sac = function(x, ... ){ +max_height.sac = function(x){ #' @export #' h = get_L_tp.sac(x) diff --git a/R/max_time.R b/R/max_time.R index c21859c..65c8ea5 100644 --- a/R/max_time.R +++ b/R/max_time.R @@ -1,10 +1,9 @@ -max_time = function(x, ...){ +max_time = function(x){ #' @export #' #' @title last time tie point #' #' @param x age-depth model (adm) or sediment accumulation curve (sac) - #' @param ... other variables, ignored #' #' @returns number, last time tie point of the age-depth model/sediment accumulation curve #' @@ -13,14 +12,14 @@ max_time = function(x, ...){ UseMethod("max_time") } -max_time.adm = function(x, ...){ +max_time.adm = function(x){ #' @export #' t = get_T_tp.adm(x) return(max(t)) } -max_time.sac = function(x, ...){ +max_time.sac = function(x){ #' @export t = get_T_tp.sac(x) return(max(t)) diff --git a/R/min_height.R b/R/min_height.R index 0e074d2..9ad7595 100644 --- a/R/min_height.R +++ b/R/min_height.R @@ -1,11 +1,10 @@ -min_height = function(x, ...){ +min_height = function(x){ #' @export #' #' @title get lowest stratigraphic tie point #' #' @param x an age-depth model (adm) or sediment accumulation curve (sac) - #' @param ... other parameters, ignored #' #' @returns number, stratigraphic position of lowest tie poin #' @@ -15,14 +14,14 @@ min_height = function(x, ...){ } -min_height.adm = function(x, ...){ +min_height.adm = function(x){ #' @export h = get_L_tp.adm(x) return(min(h)) } -min_height.sac = function(x, ...){ +min_height.sac = function(x){ #' @export h = get_L_tp.sac(x) return(min(h)) diff --git a/R/min_time.R b/R/min_time.R index d860722..22239d1 100644 --- a/R/min_time.R +++ b/R/min_time.R @@ -1,10 +1,9 @@ -min_time = function(x, ...){ +min_time = function(x){ #' @export #' #' @title first time tie point #' #' @param x age-depth model (adm) or sediment accumulation curve (sac) - #' @param ... other variables, ignored #' #' @returns number, timing of first tie point of the age-depth model/sediment accumulation curve #' @@ -13,14 +12,14 @@ min_time = function(x, ...){ UseMethod("min_time") } -min_time.adm = function(x, ...){ +min_time.adm = function(x){ #' @export #' t = get_T_tp.adm(x) return(min(t)) } -min_time.sac = function(x, ...){ +min_time.sac = function(x){ #' @export #' t = get_T_tp.sac(x) diff --git a/man/max_height.Rd b/man/max_height.Rd index 576ca49..6f1a59b 100644 --- a/man/max_height.Rd +++ b/man/max_height.Rd @@ -4,12 +4,10 @@ \alias{max_height} \title{get highest stratigraphic tie point} \usage{ -max_height(x, ...) +max_height(x) } \arguments{ \item{x}{age-depth model (adm) or sediment accumulation curve (sac)} - -\item{...}{other variables, ignored} } \value{ number, stratigraphic position of the highest stratigraphic tie point diff --git a/man/max_time.Rd b/man/max_time.Rd index 8325eb8..e1d9cd7 100644 --- a/man/max_time.Rd +++ b/man/max_time.Rd @@ -4,12 +4,10 @@ \alias{max_time} \title{last time tie point} \usage{ -max_time(x, ...) +max_time(x) } \arguments{ \item{x}{age-depth model (adm) or sediment accumulation curve (sac)} - -\item{...}{other variables, ignored} } \value{ number, last time tie point of the age-depth model/sediment accumulation curve diff --git a/man/min_height.Rd b/man/min_height.Rd index 4ac3519..f46465e 100644 --- a/man/min_height.Rd +++ b/man/min_height.Rd @@ -4,12 +4,10 @@ \alias{min_height} \title{get lowest stratigraphic tie point} \usage{ -min_height(x, ...) +min_height(x) } \arguments{ \item{x}{an age-depth model (adm) or sediment accumulation curve (sac)} - -\item{...}{other parameters, ignored} } \value{ number, stratigraphic position of lowest tie poin diff --git a/man/min_time.Rd b/man/min_time.Rd index 2a86a0c..0b6ce90 100644 --- a/man/min_time.Rd +++ b/man/min_time.Rd @@ -4,12 +4,10 @@ \alias{min_time} \title{first time tie point} \usage{ -min_time(x, ...) +min_time(x) } \arguments{ \item{x}{age-depth model (adm) or sediment accumulation curve (sac)} - -\item{...}{other variables, ignored} } \value{ number, timing of first tie point of the age-depth model/sediment accumulation curve