Skip to content

Commit

Permalink
Start polishing vignettes for pkgdown
Browse files Browse the repository at this point in the history
  • Loading branch information
zsteinmetz committed Sep 5, 2023
1 parent 3911acb commit 6071b8e
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 234 deletions.
25 changes: 14 additions & 11 deletions R/calibration.R
Expand Up @@ -8,8 +8,8 @@
#' (LOD) and limit of quantification (LOQ) in accordance with DIN 32645 (2008).
#'
#' The LOD is defined as the lowest quantity of a substance that can be
#' distinguished from the absence of that substance (blank value) within a
#' given confidence level (\code{alpha}). The LOQ is defined as the lowest quantity of
#' distinguished from the absence of that substance (blank value) within a given
#' confidence level (\code{alpha}). The LOQ is defined as the lowest quantity of
#' a substance that can be quantified/distinguished from another sample given
#' with respect to a defined confidence level (\code{k}).
#'
Expand Down Expand Up @@ -47,10 +47,10 @@
#'
#' @return
#' \code{calibration} returns an object of \code{\link[base]{class}}
#' '\code{calibration}'. \code{print()} calls the function parameters together with the
#' respective LOD and LOQ. \code{plot()} plots the respective calibration curve
#' together with the measurement values. \code{summary()} may be used to retrieve
#' the summary of the underlying model.
#' '\code{calibration}'. \code{print()} calls the function parameters together
#' with the respective LOD and LOQ. \code{plot()} plots the respective
#' calibration curve together with the measurement values. \code{summary()} may
#' be used to retrieve the summary of the underlying model.
#'
#' @author
#' Zacharias Steinmetz
Expand All @@ -69,8 +69,8 @@
#' 215-222. \doi{10.1016/S1570-0232(02)00244-1}.
#'
#' Currie, L.A. (1999). Nomenclature in evaluation of analytical methods
#' including detection and quantification capabilities:
#' (IUPAC Recommendations 1995). \emph{Analytica Chimica Acta} \bold{391}, 105-126.
#' including detection and quantification capabilities: (IUPAC Recommendations
#' 1995). \emph{Analytica Chimica Acta} \bold{391}, 105-126.
#'
#' DIN 32645 (2008). \emph{Chemical analysis - Decision limit, detection limit
#' and determination limit under repeatability conditions - Terms, methods,
Expand Down Expand Up @@ -106,7 +106,8 @@ calibration <- function(formula, data = NULL, blanks = NULL, weights = NULL,
}
}

model <- do.call(model, list(formula = formula, data = newdata, weights = newweights, ...))
model <- do.call(model, list(formula = formula, data = newdata,
weights = newweights, ...))
model$call <- match.call(expand.dots = F)
model$formula <- formula

Expand Down Expand Up @@ -177,9 +178,11 @@ plot.calibration <- function(x, interval = "conf", level = 0.95, ...) {
model <- x$model

conc <- model$model[,2]
new <- data.frame(conc = seq(min(conc), max(conc), length.out = 100 * length(conc)))
new <- data.frame(conc = seq(min(conc), max(conc),
length.out = 100 * length(conc)))
names(new) <- all.vars(model$formula)[2]
pred <- data.frame(new, predict(x$model, new, interval = interval, level = level))
pred <- data.frame(new, predict(x$model, new, interval = interval,
level = level))

plot(model$formula, data = model$model, ...)
lines(pred[, 2] ~ pred[, 1])
Expand Down
4 changes: 2 additions & 2 deletions R/theme_publish.R
Expand Up @@ -15,9 +15,9 @@
#' Zacharias Steinmetz
#'
#' @examples
#' require(ggplot2)
#' library(ggplot2)
#' p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg,
#' colour=factor(gear))) + facet_wrap( ~ am)
#' colour = factor(gear))) + facet_wrap( ~ am)
#' p
#' p + theme_publish()
#'
Expand Down
13 changes: 6 additions & 7 deletions README.md
Expand Up @@ -17,12 +17,12 @@ analysis in environmental chemistry and ecotoxicology. Provides, for example,
`calibration()` to calculate calibration curves and corresponding limits of
detection (LODs) and limits of quantification (LOQs) according to German DIN
32645 (2008). `texture()` makes it easy to estimate soil particle size
distributions from hydrometer measurements (ASTM D422-63, 2007).
Some functions of the package require **ggplot2** or **drc**.
distributions from hydrometer measurements (ASTM D422-63, 2007). Some functions
of the package require **ggplot2** or **drc**.

## Functions

Currently, the following functions are available:
The following functions are available:

### Data manipulation and analysis

Expand All @@ -34,8 +34,7 @@ Currently, the following functions are available:
* Determine particle size distributions and soil texture classes (DIN/USDA)
measured with a soil hydrometer in accordance with ASTM D422-63 (2007) using
`texture()`; see
[vignette](https://htmlpreview.github.io/?https://github.com/zsteinmetz/envalysis/blob/master/vignettes/texture.html)
for details
[vignette](https://zsteinmetz.de/envalysis/articles/texture.html) for details
* Confidence intervals `CI()`, standard errors `se()`, and root mean square
errors `rmse()`
* Various sorption isotherms `sorption()`
Expand All @@ -48,7 +47,7 @@ Currently, the following functions are available:
significant digit, using `signifig()`
* Clean, black-and-white ggplot2 theme for scientific publications
`theme_publish()`; a preview is available
[here](https://htmlpreview.github.io/?https://github.com/zsteinmetz/envalysis/blob/master/vignettes/theme_publish.html)
[here](https://zsteinmetz.de/envalysis/articles/theme_publish.html)

## Installation

Expand All @@ -57,7 +56,7 @@ Currently, the following functions are available:
### Install from CRAN (stable version)

You can install the released version of **envalysis** from
[CRAN](https://CRAN.R-project.org) with:
[CRAN](https://cran.r-project.org/package=envalysis) with:

```r
install.packages("envalysis")
Expand Down
16 changes: 8 additions & 8 deletions man/calibration.Rd

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

1 change: 1 addition & 0 deletions man/envalysis-package.Rd

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

4 changes: 2 additions & 2 deletions man/theme_publish.Rd

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

1 change: 0 additions & 1 deletion vignettes/texture.R
Expand Up @@ -19,7 +19,6 @@ tex <- texture(reading ~ blank + time + temperature, clayloam, plot = T)
tex

## ----classify-----------------------------------------------------------------
# Load soiltexture
library(soiltexture)

# Prepare data
Expand Down
74 changes: 37 additions & 37 deletions vignettes/texture.Rmd
@@ -1,5 +1,7 @@
---
title: "Particle size estimation using the hydrometer method modified from ASTM D422-63 (2007) and Bouyoucos (1927)"
title: "Particle size estimation with `texture()`"
subtitle: >
Based on the hydrometer method by ASTM D422-63 (2007) and Bouyoucos (1927)
author: "Zacharias Steinmetz"
date: "`r Sys.Date()`"
output:
Expand Down Expand Up @@ -49,36 +51,33 @@ knitr::opts_chunk$set(

### Dispersing solution

Dissolve 40 g of SHMP in 1 L of deionized water.
To facilitate complete dissolution, fill a 1 L volumetric flask with about
500 mL of deionized water and add the SHMP step-by-step
while stirring the solution with a magnetic stirrer.
The solution is stable for at least one month.
Dissolve 40 g of SHMP in 1 L of deionized water. To facilitate complete
dissolution, fill a 1 L volumetric flask with about 500 mL of deionized water
and add the SHMP step-by-step while stirring the solution with a magnetic
stirrer. The solution is stable for at least one month.

### Calibration

Hydrometers are graduated to be read at the bottom of the meniscus.
However, readings may need be taken at the top of the meniscus in opaque
soil suspensions.
Hydrometers are graduated to be read at the bottom of the meniscus. However,
readings may need be taken at the top of the meniscus in opaque soil
suspensions.

Lower the hydrometer into a 1 L cylinder filled with 125 mL of SHMP solution
and 875 mL of deionized water.
When stabilized (after about 20 s), record both the reading at the bottom (zero
or composite correction factor) and at the top of the meniscus
(meniscus correction factor).
Lower the hydrometer into a 1 L cylinder filled with 125 mL of SHMP solution and
875 mL of deionized water. When stabilized (after about 20 s), record both the
reading at the bottom (zero or composite correction factor) and at the top of
the meniscus (meniscus correction factor).

### Sample pretreatment

If the soil sample contains primarily clay or silt, weigh out 50 g of
soil (accuracy ± 0.01 g) in a 500 mL screw bottle (in 3-fold
replication). If the sample is sandy, take 100 g each. Add 125 mL SHMP solution
to the soil. Agitate the mixture for 16 h (or overnight) in a horizontal shaker.
If the soil sample contains primarily clay or silt, weigh out 50 g of soil
(accuracy ± 0.01 g) in a 500 mL screw bottle (in 3-fold replication). If the
sample is sandy, take 100 g each. Add 125 mL SHMP solution to the soil. Agitate
the mixture for 16 h (or overnight) in a horizontal shaker.

Completely transfer the soil slurry into the 1 L sedimentation cylinder
using a squirt bottle. Fill up to the 1 L mark with deionized water.
Cap the cylinder with parafilm (ensure tightness).
Agitate the slurry by turning the cylinder upside down and back 30 times
during 1 min.
Completely transfer the soil slurry into the 1 L sedimentation cylinder using a
squirt bottle. Fill up to the 1 L mark with deionized water. Cap the cylinder
with parafilm (ensure tightness). Agitate the slurry by turning the cylinder
upside down and back 30 times during 1 min.

### Measurement

Expand Down Expand Up @@ -117,11 +116,10 @@ The following table may serve as a sample template to record the data

### Data evaluation

A complete description of how to calculate the particle size
distribution from the recorded hydrometer readings is available in the
respective ASTM guideline (ASTM D422-63, 2007). The
algorithm has also been implemented into this package using the `texture()`
function:
A complete description of how to calculate the particle size distribution from
the recorded hydrometer readings is available in the respective ASTM guideline
(ASTM D422-63, 2007). The algorithm has also been implemented into this package
using the `texture()` function.

```{r texture}
# Load envalysis
Expand All @@ -140,7 +138,6 @@ Further soil classification and plotting may be done with the **soiltexture**
package.

```{r classify}
# Load soiltexture
library(soiltexture)
# Prepare data
Expand All @@ -162,16 +159,19 @@ The analyzed soil is a clay loam (German: "Toniger Lehm", Lt2).

## References

Ashworth, J., Keyes, D., Kirk, R., & Lessard, R. (2001). Standard Procedure in the
Hydrometer Method for Particle Size Analysis. *Communications in Soil Science and
Plant Analysis* **32**, 633-642. DOI: [10.1081/CSS-100103897](https://doi.org/10.1081/CSS-100103897).
Ashworth, J., Keyes, D., Kirk, R., & Lessard, R. (2001). Standard Procedure in
the Hydrometer Method for Particle Size Analysis. *Communications in Soil
Science and Plant Analysis* **32**, 633-642. DOI:
[10.1081/CSS-100103897](https://doi.org/10.1081/CSS-100103897).

ASTM D422-63 (2007). *Standard Test Method for Particle-Size Analysis of
Soils*. Technical standard. ASTM International, West Conshohocken, PA.
ASTM D422-63 (2007). *Standard Test Method for Particle-Size Analysis of Soils*.
Technical standard. ASTM International, West Conshohocken, PA.

Bouyoucos, G.J., (1927). The hydrometer as a new method for the mechanical
Bouyoucos, G.J., (1927). The hydrometer as a new method for the mechanical
analysis of soils. Soil Science 23, 343–354.

Moeys, J., Shangguan, W., Petzold, R., Minasny, B., Rosca, B., Jelinski, N.,
Zelazny, W., Souza, R.M.S., Safanelli, J.L., & ten Caten, A. (2018). *soiltexture:
Functions for Soil Texture Plot, Classification and Transformation*. URL: [https://CRAN.R-project.org/package=soiltexture](https://CRAN.R-project.org/package=soiltexture).
Zelazny, W., Souza, R.M.S., Safanelli, J.L., & ten Caten, A. (2018).
*soiltexture: Functions for Soil Texture Plot, Classification and
Transformation*. URL:
[https://CRAN.R-project.org/package=soiltexture](https://CRAN.R-project.org/package=soiltexture).
18 changes: 9 additions & 9 deletions vignettes/texture.html
Expand Up @@ -11,9 +11,9 @@

<meta name="author" content="Zacharias Steinmetz" />

<meta name="date" content="2023-07-27" />
<meta name="date" content="2023-09-05" />

<title>Particle size estimation using the hydrometer method modified from ASTM D422-63 (2007) and Bouyoucos (1927)</title>
<title>Particle size estimation with texture()</title>

<script>// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
Expand Down Expand Up @@ -350,11 +350,12 @@



<h1 class="title toc-ignore">Particle size estimation using the
hydrometer method modified from ASTM D422-63 (2007) and Bouyoucos
(1927)</h1>
<h1 class="title toc-ignore">Particle size estimation with
<code>texture()</code></h1>
<h3 class="subtitle"><p>Based on the hydrometer method by ASTM D422-63
(2007) and Bouyoucos (1927)</p></h3>
<h4 class="author">Zacharias Steinmetz</h4>
<h4 class="date">2023-07-27</h4>
<h4 class="date">2023-09-05</h4>

</div>

Expand Down Expand Up @@ -528,7 +529,7 @@ <h3>Data evaluation</h3>
distribution from the recorded hydrometer readings is available in the
respective ASTM guideline (ASTM D422-63, 2007). The algorithm has also
been implemented into this package using the <code>texture()</code>
function:</p>
function.</p>
<pre class="r"><code># Load envalysis
library(envalysis)

Expand Down Expand Up @@ -574,8 +575,7 @@ <h3>Data evaluation</h3>
# &gt; Std. Error 0.0131 0.0226 0.00954</code></pre>
<p>Further soil classification and plotting may be done with the
<strong>soiltexture</strong> package.</p>
<pre class="r"><code># Load soiltexture
library(soiltexture)
<pre class="r"><code>library(soiltexture)

# Prepare data
germansoil &lt;- data.frame(t(tex$din[&quot;Estimate&quot;,] * 100))
Expand Down

0 comments on commit 6071b8e

Please sign in to comment.