Skip to content

Commit

Permalink
creat pkgdown website for the package
Browse files Browse the repository at this point in the history
  • Loading branch information
japhir committed Jul 22, 2023
1 parent 61be1e7 commit af345cd
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
48 changes: 48 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.Rhistory
/.Rbuildignore
docs
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ Imports:
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
URL: https://japhir.github.io/clumpedcalib/
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export(d18Osw_calc)
export(filter_outliers)
export(temp_calc)
export(temp_d18Osw_calc)
importFrom(stats,coef)
6 changes: 5 additions & 1 deletion R/apply_calib_and_d18O_boot.R
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions R/clumped_calib_boot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions R/clumpedcalib-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
#' @importFrom stats coef
## usethis namespace: end
NULL
15 changes: 14 additions & 1 deletion R/equation_supported.R
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
7 changes: 2 additions & 5 deletions R/temp_calc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url: https://japhir.github.io/clumpedcalib/
template:
bootstrap: 5

7 changes: 5 additions & 2 deletions man/apply_calib_and_d18O_boot.Rd

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

3 changes: 3 additions & 0 deletions man/clumped_calib_boot.Rd

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

15 changes: 15 additions & 0 deletions man/clumpedcalib-package.Rd

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

20 changes: 19 additions & 1 deletion man/equation_supported.Rd

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

14 changes: 7 additions & 7 deletions tests/testthat/test-d18Osw_temp_calculations.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand All @@ -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),
Expand Down

0 comments on commit af345cd

Please sign in to comment.