diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..ed7650c --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,48 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.4.1 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.gitignore b/.gitignore index e5274f0..4a638bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.Rhistory /.Rbuildignore +docs diff --git a/DESCRIPTION b/DESCRIPTION index 0126f99..8aeb240 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,3 +30,4 @@ Imports: Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 +URL: https://japhir.github.io/clumpedcalib/ diff --git a/NAMESPACE b/NAMESPACE index c5db78e..b686655 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,3 +7,4 @@ export(d18Osw_calc) export(filter_outliers) export(temp_calc) export(temp_d18Osw_calc) +importFrom(stats,coef) diff --git a/R/apply_calib_and_d18O_boot.R b/R/apply_calib_and_d18O_boot.R index 8c0f873..77241ff 100644 --- a/R/apply_calib_and_d18O_boot.R +++ b/R/apply_calib_and_d18O_boot.R @@ -1,9 +1,13 @@ -#' Calculate bootstrapped mean values for age, d18O, d13C, and D47 and calculate temperature and d18Osw +#' Calculate bootstrapped means with temperature and d18Osw +#' +#' For age, d18O, d13C, and D47, from which we calculate temperature and d18Osw. #' #' @inheritParams filter_outliers #' @inheritParams bootstrap_means #' @inheritParams temp_d18Osw_calc #' @inheritParams our_summary +#' @param output Character vector specifying whether to return a `"summary"` or +#' the `"raw"` bootstrapped samples. #' @export apply_calib_and_d18O_boot <- function(data, calib, diff --git a/R/clumped_calib_boot.R b/R/clumped_calib_boot.R index 73daf19..f14da18 100644 --- a/R/clumped_calib_boot.R +++ b/R/clumped_calib_boot.R @@ -3,6 +3,7 @@ #' @param data A data.frame with columns D47, X, sd_X, and sd_D47. X stands for #' the commonly-used temperature scale, 10^6 / T^2 with T in K. #' @param Nsim Number of simulations to do for bootstrapping. +#' @returns A [tibble][tibble::tibble-package] with bootstrapped slope--intercept pairs. #' @export clumped_calib_boot <- function(data, Nsim = 1e5) { bs <- function(data, indices) { diff --git a/R/clumpedcalib-package.R b/R/clumpedcalib-package.R new file mode 100644 index 0000000..57c464c --- /dev/null +++ b/R/clumpedcalib-package.R @@ -0,0 +1,7 @@ +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +#' @importFrom stats coef +## usethis namespace: end +NULL diff --git a/R/equation_supported.R b/R/equation_supported.R index 014ad88..e1c55e2 100644 --- a/R/equation_supported.R +++ b/R/equation_supported.R @@ -1,6 +1,19 @@ #' Parse equation name into our internal simplified code. #' -#' Throws an error if not supported. +#' See details for which equations are currently supported. +#' +#' - Kim & O'Neil 1997 as recalculated by Bemis et al., 1998: +#' +#' \eqn{T = a + b(\delta_{c} - \delta_{w}) + c(\delta_{c} - \delta_{w})^2}{T = a + b(delta_c - delta_w) + c(delta_c - delta_w)^2}, +#' +#' where T is in °C, \eqn{\delta_{c}}{delta_c} is in VPDB and \eqn{\delta_{w}}{delta_w} is in VMOW. +#' +#' - Marchitto et al., 2014: +#' +#' \eqn{(\delta_{cp} - \delta_{ws} + 0.27) = -0.245\pm0.005t + 0.0011\pm0.0002t^{2} + 3.58±0.02}{(delta_cp - delta_ws + 0.27) = -0.245+-0.005t + 0.0011+-0.0002t^2 + 3.58+-0.02}. +#' +#' @param equation Character vector with equation reference. +#' @returns Character vector of cleaned up equation reference. Gives an error if it's currently not supported. equation_supported <- function(equation) { supported_equations <- c( "KimONeil1997", # NOTE: as recalculated in Bemis 1998! diff --git a/R/temp_calc.R b/R/temp_calc.R index 0868c03..acd3cd4 100644 --- a/R/temp_calc.R +++ b/R/temp_calc.R @@ -11,12 +11,9 @@ #' @export temp_calc <- function(d18Occ, d18Osw, equation = NULL) { equation <- equation_supported(equation) - if (!equation %in% supported_equations()) { - cli::cli_abort(c("Equation {equation} is not implemented", - "i" = "Feel free to submit a pull request!")) - } - if (equation == "KimONeil1997") { + # T (°C) = a + b(δc - δw) + c(δc - δw)^2 + # with a = 16.1, b = -4.64, and c = 0.09 d18Osw <- d18Osw - 0.27 # convert from VSMOW to VPDB temp <- 16.1 - 4.64 * (d18Occ - d18Osw) + 0.09 * (d18Occ - d18Osw)^2 } else if (equation == "Marchitto2014") { diff --git a/README.md b/README.md new file mode 100644 index 0000000..82f4a19 --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# `clumpedcalib`: Calculate and Apply Clumped Isotope Calibrations Using Bootstrapping + +[![](https://zenodo.org/badge/657580630.svg)](https://zenodo.org/badge/latestdoi/657580630) + +Written by [Ilja J. Kocken](https://orcid.org/0000-0003-2196-8718) Feel +free to use this stuff, as long as you adhere to the +[file:LICENSE.md](LICENSE.md) + +- Calculate bootstrapped York regression from clumped isotope + calibration data. +- Calculate bootstrapped sample means for the age, d13C, d18O, and + D47. +- Apply the bootstrapped calibration to calculate temperature and + d18Osw. +- Also comes with the classic d18Occ calibrations. See + [temp_calc()](R/temp_calc.R). +- As well as the inverses, for when you have constraints on + temperature and wish to calculate d18Osw. See + [d18Osw_calc()](R/d18Osw_calc.R) . + +## How to calculate bootstrapped averages and apply a clumped-isotope specific temperature calibration. + +To use this: + +1. Install this package `clumpedcalib`, see + [#installation](#installation). +2. Update the input calibration data + [file:dat/example_calib.csv](dat/example_calib.csv). Make sure the + column names include `X`, `D47`, `sd_X`, `sd_D47`. +3. Add your sample data at the replicate level. +4. Check to see if you like [the function that calculates + d18Osw](R/d18Osw_calc.R). Currently, you can choose from the Kim & + O\'Neil 1997 calibration, as adjusted by Bemis et al., 1998, or the + Marchitto et al., 2014 calibration. +5. Create your own definition of [filter outliers](R/filter_outliers.R) + so that it filters out bad measurements and NA\'s for your data. +6. Walk through [the example workflow](clumped-bootstrap-calibration.org) + step-by-step. +7. Have a look at [the functions](R) to better understand what's + happening. + +The bootstrapped calibration idea is based on a Matlab script written by +Alvaro Fernandez. + +# installation + +To install this development package: + +```{R} +remotes::install_github("japhir/clumpedcalib") +``` + +Or you can look at all the [functions](R) and only copy what you like. diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..a5869c2 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,4 @@ +url: https://japhir.github.io/clumpedcalib/ +template: + bootstrap: 5 + diff --git a/man/apply_calib_and_d18O_boot.Rd b/man/apply_calib_and_d18O_boot.Rd index 80547ef..a48a339 100644 --- a/man/apply_calib_and_d18O_boot.Rd +++ b/man/apply_calib_and_d18O_boot.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/apply_calib_and_d18O_boot.R \name{apply_calib_and_d18O_boot} \alias{apply_calib_and_d18O_boot} -\title{Calculate bootstrapped mean values for age, d18O, d13C, and D47 and calculate temperature and d18Osw} +\title{Calculate bootstrapped means with temperature and d18Osw} \usage{ apply_calib_and_d18O_boot( data, @@ -22,11 +22,14 @@ which are related via \code{clumpedr::revcal()}.} \item{group}{Column name of the groups.} +\item{output}{Character vector specifying whether to return a \code{"summary"} or +the \code{"raw"} bootstrapped samples.} + \item{equation}{Character vector with the equation to use. Defaults to Kim & O'Neil, 1997.} \item{Nsim}{The number of bootstraps you want to run. Defaults to the number of rows in \code{calib}.} } \description{ -Calculate bootstrapped mean values for age, d18O, d13C, and D47 and calculate temperature and d18Osw +For age, d18O, d13C, and D47, from which we calculate temperature and d18Osw. } diff --git a/man/clumped_calib_boot.Rd b/man/clumped_calib_boot.Rd index 26dff3c..2195058 100644 --- a/man/clumped_calib_boot.Rd +++ b/man/clumped_calib_boot.Rd @@ -12,6 +12,9 @@ the commonly-used temperature scale, 10^6 / T^2 with T in K.} \item{Nsim}{Number of simulations to do for bootstrapping.} } +\value{ +A \link[tibble:tibble-package]{tibble} with bootstrapped slope--intercept pairs. +} \description{ Bootstrapped clumped isotope calibration } diff --git a/man/clumpedcalib-package.Rd b/man/clumpedcalib-package.Rd new file mode 100644 index 0000000..c18388e --- /dev/null +++ b/man/clumpedcalib-package.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/clumpedcalib-package.R +\docType{package} +\name{clumpedcalib-package} +\alias{clumpedcalib} +\alias{clumpedcalib-package} +\title{clumpedcalib: Calculate and Apply Clumped Isotope Calibrations Using Bootstrapping} +\description{ +Calculate bootstrapped York regression from clumped isotope calibration data. Calculate bootstrapped sample means for the age, d13C, d18O, and D47. Apply the bootstrapped calibration to calculate temperature and d18Osw. +} +\author{ +\strong{Maintainer}: Ilja Kocken \email{i.j.kocken@uu.nl} (\href{https://orcid.org/0000-0003-2196-8718}{ORCID}) + +} +\keyword{internal} diff --git a/man/equation_supported.Rd b/man/equation_supported.Rd index 1db1471..1ff8036 100644 --- a/man/equation_supported.Rd +++ b/man/equation_supported.Rd @@ -6,6 +6,24 @@ \usage{ equation_supported(equation) } +\arguments{ +\item{equation}{Character vector with equation reference.} +} +\value{ +Character vector of cleaned up equation reference. Gives an error if it's currently not supported. +} \description{ -Throws an error if not supported. +See details for which equations are currently supported. +} +\details{ +\itemize{ +\item Kim & O'Neil 1997 as recalculated by Bemis et al., 1998: + +\eqn{T = a + b(\delta_{c} - \delta_{w}) + c(\delta_{c} - \delta_{w})^2}{T = a + b(delta_c - delta_w) + c(delta_c - delta_w)^2}, + +where T is in °C, \eqn{\delta_{c}}{delta_c} is in VPDB and \eqn{\delta_{w}}{delta_w} is in VMOW. +\item Marchitto et al., 2014: + +\eqn{(\delta_{cp} - \delta_{ws} + 0.27) = -0.245\pm0.005t + 0.0011\pm0.0002t^{2} + 3.58±0.02}{(delta_cp - delta_ws + 0.27) = -0.245+-0.005t + 0.0011+-0.0002t^2 + 3.58+-0.02}. +} } diff --git a/tests/testthat/test-d18Osw_temp_calculations.R b/tests/testthat/test-d18Osw_temp_calculations.R index 67c3934..0ddf21f 100644 --- a/tests/testthat/test-d18Osw_temp_calculations.R +++ b/tests/testthat/test-d18Osw_temp_calculations.R @@ -3,13 +3,13 @@ test_that("They're reversible", { temp_calc(d18Occ = 2, d18Osw = 0) d18Osw_calc(d18Occ = 2, temperature = 5) # is it reversible? - expect_equal(d18Osw = d18Osw_calc(d18Occ = 3, - temp = temp_calc(d18Occ = 3, - d18Osw = 0)), - 0) + expect_equal(d18Osw_calc(d18Occ = 3, + temp = temp_calc(d18Occ = 3, + d18Osw = 0)), + expected = 0) expect_equal(temp_calc(d18Occ = 3, d18Osw = d18Osw_calc(d18Occ = 3, temp = 5)), - 5) + expected = 5) expect_error(d18Osw_calc(5, 3, equation = "hoi")) expect_error(temp_calc(5, 3, equation = "hoi")) @@ -21,12 +21,12 @@ test_that("They're reversible", { d18Osw = 0, equation = "Marchitto2014"), equation = "Marchitto2014"), - 0) + expected = 0) expect_equal(temp_calc(d18Occ = 3, d18Osw = d18Osw_calc(d18Occ = 3, temp = 5, equation = "Marchitto2014"), equation = "Marchitto2014"), - 5) + expected = 5) ## # set up a plot for comparison between equations ## comparison <- expand.grid(d18Occ = seq(-10, 10),